How to clear a Service Worker cache in Firefox?

2022 Answer

In Firefox 101+, the process for unregistering all service workers:

  1. Navigate to about:debugging.
  2. Click all "Unregister Service Worker" buttons automatically by running this code in the dev console (F12):
for (let button of document.getElementsByClassName("qa-unregister-button")) { button.click(); }

Type this in the address bar of Firefox and deregister the service workers you want.

about:debugging#workers

EDIT: In newer versions #worker anchor does not works. You will have to scroll down to Service Workers section.


You can execute following code snippet in Firefox Web Console:

caches.keys().then(function (cachesNames) {
  console.log("Delete " + document.defaultView.location.origin + " caches");
  return Promise.all(cachesNames.map(function (cacheName) {
    return caches.delete(cacheName).then(function () {
      console.log("Cache with name " + cacheName + " is deleted");
    });
  }))
}).then(function () {
  console.log("All " + document.defaultView.location.origin + " caches are deleted");
});

For more information about this code snippet check Cache Web API page on MDN.

You can't clear Service Worker cache using Storage Inspector in current version of Firefox. See Storage Inspection documentation about currently available features. You can't use about:preferences#privacy or unregister Service Worker because Service Worker cache works independently of browser HTTP cache and managed only by your scripts. Relevant excerpt from Service Worker specification:

5.2 Understanding Cache Lifetimes The Cache instances are not part of the browser's HTTP cache. The Cache objects are exactly what authors have to manage themselves. The Cache objects do not get updated unless authors explicitly request them to be. The Cache objects do not expire unless authors delete the entries. The Cache objects do not disappear just because the service worker script is updated. That is, caches are not updated automatically. Updates must be manually managed. This implies that authors should version their caches by name and make sure to use the caches only from the version of the service worker that can safely operate on.