Uninstalling a PWA Service Worker

Progressive web apps are an amazing innovation that everyone should learn. But their power can sometimes be a little annoying. Often during development or production you need to remove a service worker but it is anything but obvious how to do this. Having a defunct service worker active can destroy your site experience for everyone until it is gone because the left over is based on an old site or web app.

The easiest way is to add the following to your main index.html page instead of the code that used to load the server worker, which you can always add back later.

<script>
navigator.serviceWorker.getRegistrations().then(all=>{for (let r of all) r.unregister()})
</script>

References