No response from content script for contextmenu chrome extension

拟墨画扇 提交于 2020-01-25 12:34:32

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!