微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在 manifest.json (manifest v3) 中加载时出现“Service Worker 注册失败”错误

如何解决在 manifest.json (manifest v3) 中加载时出现“Service Worker 注册失败”错误

刚开始研究 Chrome 扩展程序,这个问题让我很难过,尤其是因为我之前制作的扩展程序没有这样的问题。该项目应该是计时器,但是每当我向 console.log 添加background.js 更复杂的内容时,它都会给我上面提到的错误

manifest.json:

{
    "manifest_version": 3,"name": "Pomodoro Timer","version": "1.0.0","description": "Beta","permissions": ["storage"],"icons": {
        "16": "icon.png","48": "icon.png","128": "icon.png"
    },"action": {
        "default_icon": {
            "16": "icon.png","24": "icon.png","32": "icon.png"            
        },"default_title": "TIMER EXTENSION","default_popup": "popup/popup.html"        
    },"options_page": "options/options.html","background": {
        "service_worker": "background.js"
    }
}

background.js:

chrome.alarms.create("Timer",{
  periodInMinutes: 1 / 60,});

chrome.alarms.onAlarm.addListener((alarm) => {
  if (alarm.name === "Timer") {
    chrome.storage.local.get(["timer","isRunning"],(result) => {
      if (result.isRunning) {
        let timer = res.timer + 1;
        chrome.storage.local.set({
          timer,});
      }
    });
  }
});

chrome.storage.local.get(["timer",(result) => {
  chrome.storage.local.set({
    timer: "timer" in result ? res.timer : 0,isRunning: "isRunning" in res ? res.isRunning : false,});
});

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。