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.

skipWaiting() fails to activate waiting service worker

See original GitHub issue

Library Affected: workbox-core v4.3.1

Browser & Platform: Windows: Google Chrome 78.0.3904.108, Firefox 71.0

Issue Description: I’ve tried to follow the instructions at the docs to show a prompt, when an update is available.

After clicking the button that triggers wb.messageSW({type: 'SKIP_WAITING'});, the message is processed in the service worker, and skipWaiting() is called. Then, a warning is logged to console in chrome: Event handler of 'install' event must be added on the initial evaluation of worker script.. The service worker

I’ve also tried to do a minimal reproduction of the bug, but there, it works as intended. Any idea whats going wrong in my project?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

5reactions
jeffposnickcommented, Dec 6, 2019

As per the recipe, you need to make sure that your service worker includes

addEventListener('message', (event) => {
  if (event.data && event.data.type === 'SKIP_WAITING') {
    // Use this, and not workbox.skipWaiting()
    skipWaiting();
  }
});

and not workbox.skipWaiting() for that to work. (The skipWaiting() in that example is effectively self.skipWaiting(), and self refers to the ServiceWorkerGlobalScope.)

It’s a subtle difference, but workbox.skipWaiting() wraps the call inside of an install handler, and while that’s suitable for use outside of a message event listener, inside the listener it ends up being executed after the initial evaluation of the worker script.

2reactions
jeffposnickcommented, Sep 8, 2020

@CalebKester sorry about that confusion. In v6, we’ve deprecated usage of skipWaiting() from workbox-core because of that sort of frustration.

https://github.com/GoogleChrome/workbox/blob/6d38919ebbc9664327e19ff00302d805c8166170/packages/workbox-core/src/skipWaiting.ts#L16-L33

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
skipWaiting() method of the ServiceWorkerGlobalScope forces the waiting service worker to become the active service worker.
Read more >
Service worker and its self.skipWaiting() method
skipWaiting() method solves this problem by telling the newly installed service worker to skip the waiting state and move directly to activating ...
Read more >
Service Workers - waitUntil, skipWaiting, and claim methods
This is the third video in the Understanding Service Workers Series.This video focuses on three very powerful methods that you can use ...
Read more >
`skipWaiting()` with `StaleWhileRevalidate` the right way
To update the PWA app without leaving it, skipping the waiting phase of the new service worker is needed. Thus after location.reload() ......
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