I was curious if anyone knew a javascript based method for detecting whether the web experience was being run as a PWA (progressive web app) or it was simply being run as a
if (window.matchMedia('(display-mode: standalone)').matches) {
console.log("This is running as standalone.");
}
This answer is correct but it's worth to mention that PWA could run on plenty of display modes:
If you run your PWA in a 'fullscreen' mode it will return false so additional checks are necessary like:
function isPwa() {
return ["fullscreen", "standalone", "minimal-ui"].some(
(displayMode) => window.matchMedia('(display-mode: ' + displayMode + ')').matches
);
}
Note that window.matchMedia check will return true for the 'browser' display mode even when it's not an installed PWA app.