fix(pwa): broader PWA detection for Android WebAPK
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

Chrome WebAPK may not report display-mode: standalone. Added fallback
checks: minimal-ui, android-app:// referrer, and inverse browser mode
detection (if browser mode is supported but not matched, we're in PWA).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-03-18 10:03:08 +01:00
parent 16ba5f391a
commit c72f62508d

View File

@ -2372,7 +2372,19 @@
}
// PWA detection — set cookie for backend analytics
if (window.matchMedia('(display-mode: standalone)').matches || window.navigator.standalone) {
// WebAPK on Android may not report standalone via matchMedia reliably
var _isPWA = window.matchMedia('(display-mode: standalone)').matches
|| window.matchMedia('(display-mode: minimal-ui)').matches
|| window.navigator.standalone === true
|| document.referrer.startsWith('android-app://');
// Fallback: if browser mode query is supported but does NOT match, we're in PWA
if (!_isPWA) {
var browserMode = window.matchMedia('(display-mode: browser)');
if (browserMode.media !== 'not all' && !browserMode.matches) {
_isPWA = true;
}
}
if (_isPWA) {
document.cookie = 'pwa_mode=1; path=/; max-age=86400; SameSite=Lax';
}