简体   繁体   中英

Using setInterval in Service worker

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);

});

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

See the lifetime paragraph of the Service Workers specification .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM