我已经开发了用于上下文菜单的Chrome扩展,它工作。通过谷歌浏览器更改新API后,我的扩展程序不工作。我看到文档需要更改不赞成使用的API。但没有运气! 这里有文件,内容脚本没有回应内容脚本的Chrome扩展
manifest.json的
{
"manifest_version": 2,
"name": "ClickRight Plugin",
"version": "1.0",
"description": "Clickright utility for Chrome Browser",
"permissions":["contextMenus","tabs","https://www.gmail.com"],
"content_scripts" : [
{
"matches" : [
"http://*/*",
"https://*/*"
],
"js" : ["chromeplug.js"]
}
],
"background":
{
"page":"background.html"
}
}
background.html
包含两个脚本,clickright.js和chromeplug.js
chromeplug.js
个chrome.extension.onRequest.addListener(function(request, sender, sendResponse) {
if (request.method == "getHtml") {
..
sendResponse({key:value});});
chrome.contextMenus.create({
"title": "Trace CAL Log",
"contexts": ["page", "selection"]
});
chrome.contextMenus.onClicked.addListener(function()
{
chrome.tabs.query({
active: true,
currentWindow: true},
function(tabs) {
chrome.tabs.sendMessage(tabs[0].id,{method:"getHtml"}, function(response) {
var id=response.key;
getChromeLogs(id,tabs[0].url);
});
});
clickright.js
getChromeLogs(LOGID,URL){}
上点击右键菜单没有任何反应!我想我已经囊括了所有neccessary API。将API放在文件中可能会出错。 在此先感谢!
有什么错误?处理程序被解雇了吗?是查询返回结果?任何细节? –
我在控制台中得到这个错误消息之前,我在预期的页面中右键单击“未捕获的TypeError:无法调用未定义的方法”创建“。我没有错过权限键中contextMenu的条目.Background.html不抛出任何error.handler没有被解雇(在chrome.extension.onRequest.addListener(函数(request,sender,sendResponse){}没有执行)中的alert语句。没有响应我可以看到当我点击contextmenu.Got坚持我的发展。谢谢@Maciej! – user3328097