if (window.matchMedia('(display-mode: standalone)').matches) { console.log("This is running as standalone."); }
This answer is correct, but it is worth mentioning that PWA can work in many display modes:
- full screen mode
- autonomous
- minimum
- browser
If you run PWA in full screen mode, it will return false , so additional checks are needed, such as:
function isPwa() { var displayModes = ["fullscreen", "standalone", "minimal-ui"]; displayModes.forEach(function(displayMode) { if (window.matchMedia('(display-mode: ' + displayMode + ')').matches) { return true; } }); return false; }
Note that checking window.matchMedia will return true for the browser display mode, even if it is not a installed PWA application.
source share