How to detect if web app running standalone on Chrome mobile

An old question but significantly better solutions available today for Chrome Android.

One of the ways(cleanest IMO). You may add Web App Manifest with a 'start_url' key with a value that adds a query string parameter to your usual homepage.

ex:- if homepage url is https://www.example.com. in Web App Manifest set

    "start_url": "https://www.example.com/?user_mode=app"

Google's guide about Web app manifest:https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/


iOS and Chrome WebApp behaves different, thats the reason i came to following:

isInWebAppiOS = (window.navigator.standalone === true);
isInWebAppChrome = (window.matchMedia('(display-mode: standalone)').matches);

Same as here: Detect if iOS is using webapp


For the IOS we have window.navigator.standalone property to check..

But for Chrome on Android, it doesn't support this property. Only way to check this is by calculating screen width and height.

Below is the code to check that:

navigator.standalone = navigator.standalone || (screen.height-document.documentElement.clientHeight<40)

I got reference from below link:

Home Screen Web Apps for Android Thanks to Chrome 31


This answer comes with a huge delay, but I post it here just for other people who are struggling to find a solution.

Recently Google has implemented the CSS conditional display-mode: standalone, so there are two possible ways to detect if an app is running standalone:

Using CSS:

@media all and (display-mode: standalone) {
    /* Here goes the CSS rules that will only apply if app is running standalone */
}

Using both CSS and Javascript:

function isRunningStandalone() {
    return (window.matchMedia('(display-mode: standalone)').matches);
}
...
if (isRunningStandalone()) {
    /* This code will be executed if app is running standalone */
}

If you need more information, Google Developers has a page dedicated to this topic: https://developers.google.com/web/updates/2015/10/display-mode