问题
I have already developed chrome extension for context menu and it worked.After the change over of new API by google chrome,my extension is not working.I saw the documents need to change the deprecated API. But no luck! Here are the files,
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
Included two scripts, clickright.js and 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){}
On clicking the context menu nothing happens!Guess I have included all neccessary API. May be wrong with the placing of API in files. Thanks in Advance!
回答1:
It looks like chrome.contextMenus.create
should go into background.js, not content script.
来源:https://stackoverflow.com/questions/21882208/no-response-from-content-script-for-contextmenu-chrome-extension