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);
});
The browser may terminate the service worker at any time. Basically you can't use setTimeout reliably in a service worker. The supported way to keep a service worker alive is passing a promise to waitUntil/respondWith, but even then the browser may time out the promise and terminate the worker.
--
You received this message because you are subscribed to the Google Groups "service-worker-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to service-worker-di...@chromium.org.
To post to this group, send email to service-wor...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/service-worker-discuss/0532249f-85fd-42d7-8219-b9f773ac4cce%40chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/service-worker-discuss/CAJ_xCinyd1EHL773SvQbpybALzSzdxUuXM79s%3DR8CxH-x_qjAA%40mail.gmail.com.