如何清除Firefox中的Service Worker缓存?

Sup*_*arp 18 firefox browser-cache service-worker

在Chrome中,可以从开发工具中清除Service Worker缓存.

我们怎样才能在Firefox中实现这一目标?

我到目前为止尝试过:

  • 取消注册服务 about:serviceworkers
  • 清空下的缓存 about:preferences#privacy
  • 用来重新加载页面 Ctrl + F5

但它还在那里......

cod*_*101 22

在Firefox的地址栏中键入此内容,然后取消注册所需的服务工作者.

about:debugging#workers
Run Code Online (Sandbox Code Playgroud)

  • 提供一些更新,“#workers”锚点现在似乎不起作用。我输入“about:debugging”并向下滚动 (2认同)

Leo*_*lev 21

您可以在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");
});
Run Code Online (Sandbox Code Playgroud)

有关此代码段的详细信息,请查看MDN上的" 缓存Web API"页面.

您无法在当前版本的Firefox中使用Storage Inspector清除Service Worker缓存.请参阅有关当前可用功能的存储检查文档 您无法使用about:preferences#privacy或取消注册Service Worker,因为Service Worker缓存独立于浏览器HTTP缓存而只能由您的脚本管理.服务工作者规范的相关摘录:

5.2了解缓存生存期 缓存实例不是浏览器HTTP缓存的一部分.Cache对象正是作者必须自己管理的对象.除非作者明确要求,否则不会更新Cache对象.除非作者删除条目,否则Cache对象不会过期.Cache对象不会因为更新服务工作者脚本而消失.也就是说,缓存不会自动更新.必须手动管理更新.这意味着作者应该按名称对其缓存进行版本化,并确保仅使用可以安全操作的服务工作者版本的缓存.


dot*_*hen 8

2022答案

在 Firefox 101+ 中,取消注册所有 Service Worker 的过程:

  1. 导航至“关于:调试”。
  2. 通过在开发控制台 (F12) 中运行以下代码来自动单击所有“取消注册 Service Worker”按钮:
for (let button of document.getElementsByClassName("qa-unregister-button")) { button.click(); }
Run Code Online (Sandbox Code Playgroud)


小智 1

如上所述,目前还不可能。但删除缓存条目和缓存已经实现,应该很快就会推出(https://bugzilla.mozilla.org/show_bug.cgi?id=1304297)。例如,它已经在 Firefox 开发者版中提供。

  • @Supersharp 怎么办? (7认同)