beforeinstallprompt does not work on console.log

安稳与你 提交于 2021-02-11 12:52:48

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!