mirror of
https://github.com/faisalman/ua-parser-js.git
synced 2025-09-27 07:58:45 +03:00
Add new helper method isPWA()
to check for standalone mode. Also fix #728
This commit is contained in:
parent
a74ace8dd1
commit
50c15ad5a8
4
src/helpers/ua-parser-helpers.d.ts
vendored
4
src/helpers/ua-parser-helpers.d.ts
vendored
@ -7,9 +7,11 @@ import { IResult } from "../main/ua-parser";
|
||||
declare function isAppleSilicon(res: IResult): boolean;
|
||||
declare function isChromiumBased(res: IResult): boolean;
|
||||
declare function isFrozenUA(ua: string): boolean;
|
||||
declare function isPWA(): boolean;
|
||||
|
||||
export {
|
||||
isAppleSilicon,
|
||||
isChromiumBased,
|
||||
isFrozenUA
|
||||
isFrozenUA,
|
||||
isPWA
|
||||
}
|
@ -15,8 +15,19 @@ const isChromiumBased = (res) => res.engine.is(Engine.BLINK);
|
||||
|
||||
const isFrozenUA = (ua) => /^Mozilla\/5\.0 \((Windows NT 10\.0; Win64; x64|Macintosh; Intel Mac OS X 10_15_7|X11; Linux x86_64|X11; CrOS x86_64 14541\.0\.0|Fuchsia|Linux; Android 10; K)\) AppleWebKit\/537\.36 \(KHTML, like Gecko\) Chrome\/\d+\.0\.0\.0 (Mobile )?Safari\/537\.36/.test(ua);
|
||||
|
||||
const isPWA = () => window && (window.matchMedia('(display-mode: standalone)').matches ||
|
||||
// iOS
|
||||
navigator.standalone ||
|
||||
// Android
|
||||
document.referrer.startsWith('android-app://') ||
|
||||
// Windows
|
||||
window.Windows ||
|
||||
/trident.+(msapphost|webview)\//i.test(navigator.userAgent) ||
|
||||
document.referrer.startsWith('app-info://platform/microsoft-store'));
|
||||
|
||||
module.exports = {
|
||||
isAppleSilicon,
|
||||
isChromiumBased,
|
||||
isFrozenUA
|
||||
isFrozenUA,
|
||||
isPWA
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user