Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ServiceWorkerRegistration.update() skip waiting phase and activate the new service worker?

I was reading NekR/offline-plugin source code. In the update method it calls browser's ServiceWorker.update().

I want to know that if this method force activate the new service worker(i.e. skipWaiting) or it just pull the latest service worker and waiting for user to detach service workers from browser(i.e. waiting phase).

like image 903
Arthur Avatar asked Oct 20 '25 09:10

Arthur


2 Answers

No, it does not force the new SW to take control. That could potentially break many applications. Install event is executed and the SW script itself is responsible for calling skipWaiting etc. if it wants to.

You can see that from the spesification of the Service Worker update process. SkipWaiting is not scheduled. https://www.w3.org/TR/service-workers-1/#dom-serviceworkerregistration-update

like image 165
pate Avatar answered Oct 22 '25 03:10

pate


I know that this already has an answer, but for those that want a straightforward way to bypass the "skip waiting", just add the line below alone in your service-worker.js

self.skipWaiting();

So next time you are updating your service-worker.js, it will "skip waiting".

like image 34
Francisco Gomes Avatar answered Oct 22 '25 05:10

Francisco Gomes