fix(pwa): suppress install dialog in in-app browsers
This commit is contained in:
@@ -1,41 +0,0 @@
|
||||
/**
|
||||
* 浏览器 / 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);
|
||||
},
|
||||
|
||||
/** 当前是否以 PWA standalone 模式运行 */
|
||||
isPWAStandalone(): boolean {
|
||||
if (typeof window === "undefined") return false;
|
||||
return (
|
||||
window.matchMedia?.("(display-mode: standalone)").matches === true ||
|
||||
// iOS Safari 旧版
|
||||
(navigator as Navigator & { standalone?: boolean }).standalone === true
|
||||
);
|
||||
},
|
||||
};
|
||||
@@ -2,5 +2,4 @@
|
||||
* @file Automatically generated by barrelsby.
|
||||
*/
|
||||
|
||||
export * from "./browser-detect";
|
||||
export * from "./media-recorder";
|
||||
|
||||
Reference in New Issue
Block a user