-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathruntimeMode.ts
More file actions
32 lines (31 loc) · 1.25 KB
/
Copy pathruntimeMode.ts
File metadata and controls
32 lines (31 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* runtimeMode — detects whether the app is currently running as an
* installed, standalone PWA (added to home screen / launched in its own
* window, no browser chrome) vs. a normal browser tab.
*
* This is a display-mode check only — the `display-mode: standalone` media
* query (with the iOS Safari `navigator.standalone` fallback, which doesn't
* support that query). It's not a fingerprinting signal: it isn't combined
* with anything else, isn't sent anywhere, and doesn't distinguish one
* visitor from another — it only distinguishes *how* this page happens to be
* displayed right now. So it lives outside the Observer.ts §6 detector
* whitelist rather than in it; see `sessionState.ts` for its one use.
*/
export function isStandalonePwa(): boolean {
try {
if (
typeof window !== 'undefined' &&
window.matchMedia?.('(display-mode: standalone)').matches
) {
return true;
}
// iOS Safari never supported the display-mode media query; it exposes this instead.
return (
typeof navigator !== 'undefined' &&
(navigator as Navigator & { standalone?: boolean }).standalone === true
);
} catch {
// window/navigator/matchMedia unavailable in this environment (e.g. tests).
return false;
}
}