Using setInterval in Service worker

那年仲夏 提交于 2020-05-13 10:52:50

问题


Please I want to use setInterval which shows a notification every 5 seconds inside my service worker javascript file and it works fine at first but gradually after about 20 seconds it stops working

Here is the part where timer is initialized in the service worker java script file

self.addEventListener('activate', function(event) {
  setInterval(function()
   {

     self.registration.showNotification("title", {
       body: "test"
     });


   },5000);

});

回答1:


Service workers have a limited lifetime, you can't keep them alive forever.

See the lifetime paragraph of the Service Workers specification.



来源:https://stackoverflow.com/questions/37080706/using-setinterval-in-service-worker

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