首页 > 解决方案 > PWA 应用 beforeInstallPrompt 不触发其他浏览器只会触发 Chrome 浏览器

问题描述

在 PWA Reactjs 应用程序 beforeinstallprompt 内部仅在 Chrome 移动和桌面浏览器中触发。我想像 Chrome 一样触发或触发其他浏览器。我做错了什么。

在 App.js 中添加带有 useEffect 的 EventListener。

   useEffect(() => {
        window.addEventListener("beforeinstallprompt", (e) => {
            // Prevent the mini-infobar from appearing on mobile
            e.preventDefault();
            // Stash the event so it can be triggered later.
            deferredPrompt = e;
            // Update UI notify the user they can install the PWA
            setInstallable(true);
        });

        window.addEventListener('appinstalled', () => {
            // Log install to analytics
            console.log('INSTALL: Success');
        });
    }, []);

但不触发其他浏览器只触发chrome浏览器......

标签: javascriptreactjsbrowserprogressive-web-appshomescreen

解决方案


beforeinstallprompt事件目前仅在 Chrome、Edge 和三星 Internet 中触发。Safari 允许用户安装 PWA,但用户必须自己安装,方法是单击“共享”按钮,然后单击“添加到主屏幕”。


推荐阅读