Javascript Can';t获取chrome上下文菜单以显示chrome扩展
我已经阅读了其他关于这一点的帖子,但我似乎仍然不知道我的chrome contentMenu api实现有什么问题。我刚刚从ChromeAPI教程中复制了代码,没有出现任何错误,但右键单击时,它不会显示在菜单中 我错过什么了吗 清单 background.js 编辑---Javascript Can';t获取chrome上下文菜单以显示chrome扩展,javascript,jquery,google-chrome,google-chrome-extension,contextmenu,Javascript,Jquery,Google Chrome,Google Chrome Extension,Contextmenu,我已经阅读了其他关于这一点的帖子,但我似乎仍然不知道我的chrome contentMenu api实现有什么问题。我刚刚从ChromeAPI教程中复制了代码,没有出现任何错误,但右键单击时,它不会显示在菜单中 我错过什么了吗 清单 background.js 编辑--- 仍然不确定我的代码出了什么问题,但是来自PostWorks的ExpertSystem示例编写chrome.contextMenus.create在窗口外。onload。而警报在后台不起作用。js编写chrome.context
仍然不确定我的代码出了什么问题,但是来自PostWorks的ExpertSystem示例编写
chrome.contextMenus.create
在窗口外。onload
。而警报
在后台不起作用。js编写chrome.contextMenus。在窗口外创建。onload
。而alert
在后台不起作用。js是否会触发警报?@levi是的-它会在我重新加载扩展时立即触发,但不会在我重新加载新窗口时触发(我认为这很正常,对吧?)当你说“我没有收到任何错误”时,你是否检查了后台页面的JavaScript控制台?(您可以通过单击中相应的背景页链接来打开它chrome://extensions/.Is 警报触发?@levi是的-它会在我重新加载扩展时立即触发,但不会在我重新加载新窗口时触发(我认为这是正常的,但正确吗?)?(您可以通过单击中相应的背景页链接来打开它chrome://extensions/.
{
"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"
}
}
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);
}