Hacky way to detect if app was launched in standalone mode in Chromium (with manifest.json) without problems with AppCache
(and possibly ServiceWorker
).
As suggested on one of the Google Developers sites, one may use search params in start_url
of the manifest.json
to notify page about that it was launched in standalone mode: start_url: '/?standalone'
.
This works well unless your page uses AppCache
(or ServiceWorker
). In case of AppCache
, every url with different search params is treated as separate entry in cache. So if you have listed /
path in AppCache
and naively used start_url: '/?standalone'
in your manifest.json
, then your Web App won't work offline from the Home Screen.
_With ServiceWorker
, however, there is few ways to fix this directly in its code, like ignoreSearch
option for match()
method (currently not supported in Chromium) or just traversing cache entries manually and comparing new URL(event.request.url).pathname
with stored request `new URL(...).path