Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically update service worker if update() is not available

How can I programmatically update service worker since ServiceWorkerRegistration.update() has not been implemented in Chrome yet? Is there an alternative?

like image 862
Lewis Avatar asked Oct 27 '25 02:10

Lewis


2 Answers

I assume you got this by now but I think you want serviceWorker.skipWaiting()

like image 124
David Scales Avatar answered Oct 29 '25 05:10

David Scales


From the spec.

if ('serviceWorker' in navigator) {
  navigator.serviceWorker.register('/sw-test/sw.js', {scope: 'sw-test'}).then(function(registration) {
    // registration worked
    console.log('Registration succeeded.');
    button.onclick = function() {
      registration.update();
    }
  }).catch(function(error) {
    // registration failed
    console.log('Registration failed with ' + error);
  });
};
like image 27
Sten Muchow Avatar answered Oct 29 '25 06:10

Sten Muchow



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!