问题
on https://www.zamanha.com/sw.js on self.addEventListener('beforeinstallprompt', (e) => { the console.log() does not work. anyone?
回答1:
the answer is in below. but it is very important to put it in the main.js that runs service worker like sw.js. after regissteration of service worker
if ('serviceWorker' in navigator) {
navigator.serviceWorker.register('/sw.js')
} else {
console.log('CLIENT: service worker is not supported.');
}
this code ----->
var deferredPrompt;
self.addEventListener('beforeinstallprompt', function (e) {
console.log('beforeinstallprompt Event fired');
e.preventDefault();
deferredPrompt = e.originalEvent;
return false;
});
来源:https://stackoverflow.com/questions/65354810/beforeinstallprompt-does-not-work-on-console-log