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

Provide a way to ask the waiting Service Worker to skip waiting from the outside #1223

Closed
dfabulich opened this issue Nov 13, 2017 · 1 comment

Comments

@dfabulich
Copy link

It's a common practice to ask users to click an "refresh" or "update" button when a new Service Worker is waiting. The normal way to actually kick off the update is to post a message to the Service Worker, arranging a convention under which the SW can call skipWaiting() in the Service Worker's own scope.

It would be convenient if the ServiceWorker object returned by ServiceWorkerRegistration.waiting had a skipWaiting() method, so developers wouldn't have to configure a message listener at all. Combined with #1222, you could write code like this:

navigator.serviceWorker.addEventListener('controllerchange', () => window.location.reload());
navigator.serviceWorker.waiting().then(reg => {
  if (confirm('refresh now?')) reg.waiting.skipWaiting();
});

(Uh, don't actually use confirm() in production; it's just convenient for this example.)

@mkruisselbrink
Copy link
Collaborator

Sounds like a duplicate of #1016?

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

No branches or pull requests

2 participants