question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service worker skipWaiting not activating workbox service worker

See original GitHub issue

Library Affected: workbox-sw.

Browser & Platform: All

Issue or Feature Request Description: *I have migrated from SW-Precache to workbox service worker, and during the process, I’ve updated service worker filename from ‘service-worker.js’ to ‘service-worker-mobile.js’ and also added workbox.skipWaiting() in the new service worker file, implying that as soon as new service worker file is downloaded, and installed, it should get activated, but, I can still see my old service worker file running. Any help here? *

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
jeffposnickcommented, Dec 3, 2020

By the way, workbox-window v6 has a new helper method, messageSkipWaiting(), that can be used from a web page client and will always use postMessage({type: 'SKIP_WAITING'}) to the correct service, waiting service worker instance.

3reactions
cilliemalancommented, Dec 3, 2020

I see the same thing. Service worker doesn’t update even though skipWaiting is called, no other tabs open, no waitUntil.

If anyone googles this issue 👆 and gets here, this happens when you call self.skipWaiting on the already activated (i.e. old) service worker instead of the installed and waiting (i.e. new) service worker.

AFAIK it is not possible to activate the newly installed service worker from within the old one, but you can send the new service worker a message from the old one like so:

self.registration.waiting.postMessage({type:'SKIP_WAITING'})

However, you probably want to send this message from a client (i.e. a web page) instead. In this case make sure you are sending the correct registartion the message.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service Worker skipWaiting unable to activate currently ...
The 'waiting' state cannot be found in the typescript definitions: type ServiceWorkerState = "installing" | "installed" | "activating" | " ...
Read more >
ServiceWorkerGlobalScope.skipWaiting() - Web APIs | MDN
The ServiceWorkerGlobalScope.skipWaiting() method of the ServiceWorkerGlobalScope forces the waiting service worker to become the active ...
Read more >
`skipWaiting()` with `StaleWhileRevalidate` the right way
skipWaiting () may not work properly. ... By default, a service worker takes over the page from start to end, even if the...
Read more >
Service worker and its self.skipWaiting() method
The ServiceWorker. skipWaiting() method solves this problem by telling the newly installed service worker to skip the waiting state and move ...
Read more >
Handling Service Worker updates – how to keep the app ...
Not applying the Service Worker update might mean that our outdated Service ... skipWaiting() from within the new Service Worker – it immediately...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found