Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add message event listener when skipWaiting: false #1753

Closed
jeffposnick opened this issue Nov 7, 2018 · 2 comments
Closed

Add message event listener when skipWaiting: false #1753

jeffposnick opened this issue Nov 7, 2018 · 2 comments

Comments

@jeffposnick
Copy link
Contributor

jeffposnick commented Nov 7, 2018

Library Affected:
workbox-build

When developers use the Workbox build tools in generateSWmode, and they set skipWaiting: false, we should consider adding in some boilerplate to the generated service worker that will listen to a message event and call skipWaiting() in response to a specific command that could be sent from the client page.

This would allow developers to follow recipes like https://developers.google.com/web/tools/workbox/guides/advanced-recipes#offer_a_page_reload_for_users while still using generateSW (instead of injectManifest) mode if they prefer.

The change could be added to

<% if (skipWaiting) { %>workbox.skipWaiting();<% } %>

with an else clause that would look like:

self.addEventListener('message', (event) => {
  // What should this check for?
  if (event.data === '...') {
    self.skipWaiting();
  }
});

The main thing to decide is what the event.data check should look like. This should presumably be coordinated with the work being done on the workbox-window library by @philipwalton.

@cintrzyk
Copy link

cintrzyk commented Jan 9, 2019

shouldn't be self.skipWaiting() rather than workbox.skipWaiting()? as I see workbox.skipWaiting() sets a listener instead of forcing a service worker to become active immediately 🤔

🤞 can't wait for it

@jeffposnick
Copy link
Contributor Author

We're going to go ahead and implement this ahead of the full workbox-messages package, and just add an explicit message listener and use event.data.type === 'SKIP_WAITING' as the check. That should end up being compatible with the format we have planned for workbox-messages

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants