From d689ee1f1479597c3a3d8d4a981c5183819df3d2 Mon Sep 17 00:00:00 2001 From: cmg8431 Date: Fri, 21 Jun 2024 19:39:31 +0900 Subject: [PATCH] feat: enhance mobile user agent detection accuracy --- src/userAgent.ts | 4 ++-- src/utils.ts | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/userAgent.ts b/src/userAgent.ts index a1814b6..5c68533 100644 --- a/src/userAgent.ts +++ b/src/userAgent.ts @@ -1,5 +1,5 @@ import { AgentInfo } from "./types"; -import { getUserAgentString, findPreset } from "./utils"; +import { getUserAgentString, findPreset, checkIfMobile } from "./utils"; import { WEBVIEW_PRESETS, CHROMIUM_PRESETS, BROWSER_PRESETS, OS_PRESETS, WEBKIT_PRESETS } from "./presets"; export function isWebView(userAgent: string): boolean { @@ -8,7 +8,7 @@ export function isWebView(userAgent: string): boolean { export function getLegacyAgent(userAgent?: string): AgentInfo { const nextAgent = getUserAgentString(userAgent); - const isMobile = !!/mobi/g.exec(nextAgent); + const isMobile = checkIfMobile(nextAgent); const browser = { name: "unknown", version: "-1", diff --git a/src/utils.ts b/src/utils.ts index 73dd1ed..d640942 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -108,3 +108,6 @@ export function findBrand(brands: NavigatorUABrandVersion[], preset: PresetInfo) return execRegExp(`${preset.test}`, brand.toLowerCase()); }); } +export function checkIfMobile(userAgent: string): boolean { + return /Mobile|iP(hone|od|ad)|Android|BlackBerry|IEMobile|Kindle|NetFront|Silk-Accelerated|(hpw|web)OS|Fennec|Minimo|Opera M(obi|ini)|Blazer|Dolfin|Dolphin|Skyfire|Zune/.test(userAgent); +}