即使在符合所有 PWA 规范并在 Light House 上进行检查后,添加到主屏幕也不会提示。
我试过下面的代码来检查应用程序是否已经安装。但是 appinstalled 事件没有被触发并且 beforeinstallprompt 事件被成功触发。
// 已安装应用
window.addEventListener('appinstalled', (evt) => {
app.logEvent('a2hs', 'installed');
});
// 安装前提示
window.addEventListener('beforeinstallprompt', (event) => {
event.preventDefault();
deferredPrompt = event;
});```
// manifest.json
`{
"name": "demo",
"short_name": "demo",
"icons": [{
"src": "/static/public/icon/icon-192x192.png",
"sizes": "512x512",
"type": "image/png"
},
{
"src": "/static/public/icon/icon-512x512.png",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "/",
"orientation": "portrait",
"display": "standalone",
"theme_color": "#085689",
"background_color": "#085689",
"gcm_sender_id": "103xx3xxx50x",
"gcm_user_visible_only": true
}
`
// service worker
`self.addEventListener('fetch', (event) => {
console.log('event', event);
});`