Chrome Extension Service Worker不活动之后“清除站点数据”

发布于 2025-01-18 15:13:25 字数 502 浏览 3 评论 0原文

我的清单 v3 扩展中有一个非常简单的后台脚本,它基本上等待消息,然后从同步存储中检索一个值,如下所示:

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  chrome.storage.sync.get("value", ({ value }) => {
    ... do some stuff
  }
}

现在这工作正常,直到我转到扩展的 DevTools -> 。应用->存储->清除站点数据。

之后,我的服务工作线程始终处于“不活动”状态,并且当我向其发送消息时不会变为活动状态。仅当我转到 chrome://extensions 并禁用/启用扩展时,服务工作线程才会再次开始运行。

最奇怪的是我的 popup.js 实际上仍然可以从同步存储中获取值。清除站点数据后怎么可能?

I have a very simple background script in my manifest v3 extension that basically waits for messages and then retrieves a value from sync storage like so:

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  chrome.storage.sync.get("value", ({ value }) => {
    ... do some stuff
  }
}

Now this works fine until i goto the DevTools of my extension -> Application -> Storage -> Clear site data.

After that my service worker is always "inactive" and does not become active when I send messages to it. Only when I go to chrome://extensions and disable/enable the extension the service worker starts functioning again.

The weirdest thing is that my popup.js can actually still get the value from sync storage. How is that possible after I clear the site data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文