How to uninstall a Service Worker with JavaScript?

Spread the love

Sometimes, we want to uninstall a Service Worker with JavaScript.

In this article, we’ll look at how to uninstall a Service Worker with JavaScript.

How to uninstall a Service Worker with JavaScript?

To uninstall a Service Worker with JavaScript, we can get allk the worker registrations and unregister them.

For instance, we write

const registrations = await navigator.serviceWorker.getRegistrations();

for (let registration of registrations) {
  registration.unregister();
}

to get all registered service workers as an array with navigator.serviceWorker.getRegistrations.

Then we loop through the registered workers and unregister them with unregister with the for-of loop.

Conclusion

To uninstall a Service Worker with JavaScript, we can get allk the worker registrations and unregister them.

Leave a Reply

Your email address will not be published.