gpt4 book ai didi

javascript - 无法为 chrome 扩展显示 chrome 上下文菜单

转载 作者:行者123 更新时间:2023-12-02 14:33:34 24 4
gpt4 key购买 nike

我已经浏览了有关此问题的其他帖子,但我似乎仍然无法弄清楚我的 chrome contentMenu api 实现有什么问题。我刚刚从 Chrome API 教程中复制了代码,没有收到任何错误,但当我右键单击时,它没有显示在菜单中。

我错过了什么吗?

list

 {
"manifest_version": 2,

"name": "Chrome extension practice",
"description": "Practice",
"version": "1.0",
"content_scripts":
[
{
"matches": ["*://*/*"],
"js": ["bower_components/jquery/dist/jquery.min.js", "script.js"],
"run_at": "document_end"
}
],

"permissions": [
"storage",
"contextMenus",
"background",
"https://twitter.com/",
"http://twitter.com/"
],

"background": {
"scripts": ["background.js"]
},

"browser_action": {
"default_title": "Practice",
"default_icon": "fa-moon.png",
"default_popup": "popup.html"
}
}

background.js

 window.onload = function() {
//CONTEXT MENU this should go somewhere else, but we'll need to resolve onload conflict
alert("Background script loaded");
chrome.contextMenus.create({
id: "custom-context-a",
title: "Hide Tweet",
contexts: ["launcher", "all"],
}, function(){
console.log(chrome.runtime.lastError);
});

chrome.contextMenus.onClicked.addListener(contextClicked.bind(this));
};

function contextClicked(e){
console.log(e.menuItemId);
}

编辑---

仍然不确定我的代码有什么问题,但 ExpertSystem 的示例来自 this发布作品

最佳答案

window.onload之外写入chrome.contextMenus.create。并且alert在background.js中不起作用

关于javascript - 无法为 chrome 扩展显示 chrome 上下文菜单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37645943/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com