【问题标题】:Can`t add new item to context menu in Chrome (manifest 3)无法将新项目添加到 Chrome 中的上下文菜单(清单 3)
【发布时间】:2022-08-02 18:02:59
【问题描述】:

在 Manifest 3 到 Manifest 3 的迁移过程中,我遇到了一些困难:没有任何效果。 我开发了一个简单的Chrome 扩展程序在上下文菜单中添加一个新项目,因此您可以在某些网站中搜索插入的文本。它在清单 2 中正常工作,但在清单 3 中不能正常工作。 所以有清单代码(3)

{
  \"manifest_version\": 3,
  \"name\": \"name\",
  \"short_name\": \"shortN\",
  \"description\": \"This extension will work someday I hope so\",
  \"background\": [{
    \"service_worker\": [ \"background.js\" ]
  }],
  \"icons\": {
    \"128\": \"icons/128.png\",
    \"48\": \"icons/48.png\",
    \"32\": \"icons/32.png\",
    \"16\": \"icons/16.png\"
  },
  \"permissions\": [ \"contextMenus\", \"tabs\", \"activeTab\" ],
  \"version\": \"1.3\"
}

以及背景代码示例

chrome.runtime.onInstalled.addListener(function() {
    chrome.contextMenus.create({
        title: \"title\",
        contexts: [\"selection\"],
        id: \"title1\"
    });
});

chrome.contextMenus.onClicked.addListener(function (info, tab) {
    if (info.menuItemId === \"title1\") {
        let getToSite = \"https://*\" + info.selectionText
        chrome.tabs.create({index: tab.index + 1, url: getQ, selected: true});
    }
})

有人可以看看并说什么s wrong with it? Im 也是 JS 的新手(比如,三天新),所以我很欣赏简单的解释 谢谢!

  • 删除background 部分中的所有四个[]

标签: javascript google-chrome-extension manifest.json chrome-extension-manifest-v3


【解决方案1】:
"background": {
    "service_worker": "background.js"
},

“service_worker”是一个字符串,
不 [ ]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-08
    • 1970-01-01
    相关资源
    最近更新 更多