fix(pwa): suppress install dialog in in-app browsers

This commit is contained in:
2026-06-17 16:19:21 +08:00
parent 62468ffc6a
commit f39e7e0672
3 changed files with 2 additions and 10 deletions
+32
View File
@@ -0,0 +1,32 @@
/**
* 浏览器 / WebView 检测
*
* 原始 Dart: `lib/utils/browser_detector.dart`
*
* 主要用例:
* - 嵌入 Facebook / 微信 / 微博内嵌浏览器时,给用户提示「在外部浏览器打开」。
* - 判断 PWA 模式(standalone)。
*/
export const BrowserDetector = {
/** 当前是否在 Facebook 内嵌浏览器 */
isFacebookInAppBrowser(ua: string | null = null): boolean {
if (typeof navigator === "undefined" && !ua) return false;
const userAgent = ua ?? (typeof navigator !== "undefined" ? navigator.userAgent : "");
return /FBAN|FBAV|Instagram/i.test(userAgent);
},
/** 当前是否在微信内嵌浏览器 */
isWeChatInAppBrowser(ua: string | null = null): boolean {
if (typeof navigator === "undefined" && !ua) return false;
const userAgent = ua ?? (typeof navigator !== "undefined" ? navigator.userAgent : "");
return /MicroMessenger/i.test(userAgent);
},
/** 当前是否在 WebView(不通用;仅作 best-effort 判断) */
isInAppBrowser(ua: string | null = null): boolean {
if (typeof navigator === "undefined" && !ua) return false;
const userAgent = ua ?? (typeof navigator !== "undefined" ? navigator.userAgent : "");
return /WebView|; wv\)|FBAN|FBAV|MicroMessenger|Instagram|Line\//i.test(userAgent);
},
};