我已經開發了用於上下文菜單的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