Delete Service Worker on Safari

Delete Service Worker on Safari

To delete a service worker on Safari, you can follow these steps:

  1. Open Safari Developer Console (Press Command + Option + C)
  2. Copy and paste the following JavaScript code into the console:
1
2
3
4
5
6
7
navigator.serviceWorker.getRegistrations().then(function (registrations) {
for (let registration of registrations) {
registration.unregister().then(function () {
console.log("Service Worker Unregistered:", registration.scope)
})
}
})

This code will:

  1. Get all registered service workers using navigator.serviceWorker.getRegistrations()
  2. Loop through each registration
  3. Unregister each service worker using the unregister() method
  4. Log a confirmation message with the scope of the unregistered service worker

You can verify that the service worker has been successfully removed by:

  1. Opening Safari Developer Tools
  2. Going to the Application tab
  3. Checking the Service Workers section - it should now be empty

Note: After unregistering the service worker, you might need to close all tabs and restart Safari for the changes to take full effect.