javascript - 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浏览器......
解决方案
该beforeinstallprompt
事件目前仅在 Chrome、Edge 和三星 Internet 中触发。Safari 允许用户安装 PWA,但用户必须自己安装,方法是单击“共享”按钮,然后单击“添加到主屏幕”。
推荐阅读
- c++ - 虚幻引擎 4.25、stdlib C++ 17/20 和 Visual Studio Code 之间的状态和/或集成?
- java - 如何在我的 main 方法中访问布尔数组的辅助方法?
- python - Python Pandas - 处理 CSV 文件的文件夹并输出最终组合的 CSV
- php - 修复 Wordpress 5.5 更新后的分页
- javascript - 如何快速编辑json
- actionscript-3 - 如何在 ActionScript 3 中创建具有共享代码的库?
- python-3.x - Scapy 2.4.4 - Py 3.7.9 - TypeError:无法将 str 连接到字节
- class - 为什么使用简单类的访问器和修改器?
- c++ - 从 C++ 读取时 QML 组合框的 CurrentText 属性不会改变
- javascript - 如果我使用模块化 CSS,如何将 CSS 从父组件添加到子组件