From f39e7e0672ad72f7663be58333e24b0176d6f980 Mon Sep 17 00:00:00 2001 From: chenhang Date: Wed, 17 Jun 2026 16:19:21 +0800 Subject: [PATCH] fix(pwa): suppress install dialog in in-app browsers --- src/app/chat/components/pwa-install-overlay.tsx | 2 ++ src/integrations/index.ts | 1 - src/{integrations => utils}/browser-detect.ts | 9 --------- 3 files changed, 2 insertions(+), 10 deletions(-) rename src/{integrations => utils}/browser-detect.ts (79%) diff --git a/src/app/chat/components/pwa-install-overlay.tsx b/src/app/chat/components/pwa-install-overlay.tsx index dddfc007..fc9a71a2 100644 --- a/src/app/chat/components/pwa-install-overlay.tsx +++ b/src/app/chat/components/pwa-install-overlay.tsx @@ -14,6 +14,7 @@ */ import { useEffect } from "react"; +import { BrowserDetector } from "@/utils/browser-detect"; import { SpAsyncUtil } from "@/utils/storage"; import { pwaUtil } from "@/utils/pwa"; @@ -32,6 +33,7 @@ export function PwaInstallOverlay() { // isInstalled() 检查 standalone display-mode(避免给已安装用户再弹) if (!pwaUtil.isSupported()) return; if (pwaUtil.isInstalled()) return; + if (BrowserDetector.isInAppBrowser()) return; // 提前挂 beforeinstallprompt 监听,避免用户点 OK 时事件已在更早时机丢失。 pwaUtil.prepareInstallPrompt(); diff --git a/src/integrations/index.ts b/src/integrations/index.ts index 9652de67..30be615f 100644 --- a/src/integrations/index.ts +++ b/src/integrations/index.ts @@ -2,5 +2,4 @@ * @file Automatically generated by barrelsby. */ -export * from "./browser-detect"; export * from "./media-recorder"; diff --git a/src/integrations/browser-detect.ts b/src/utils/browser-detect.ts similarity index 79% rename from src/integrations/browser-detect.ts rename to src/utils/browser-detect.ts index fbcd1d5f..4f473193 100644 --- a/src/integrations/browser-detect.ts +++ b/src/utils/browser-detect.ts @@ -29,13 +29,4 @@ export const BrowserDetector = { 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 - ); - }, };