在 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 (将#修改为@)