0
我的清單:Chrome擴展:端口:無法建立連接
{
"name":"name",
"version":"0.1",
"manifest_version":2,
"description":"name app",
"background":{
"scripts":[
"scripts/modernizr.min.js",
"scripts/background.js"
],
"persistent": false
},
"content_scripts": [
{
"matches": ["https://*/*", "http://*/*"],
"js": ["scripts/content.js"],
"run_at": "document_end"
}
],
"permissions":[
"contextMenus",
"tabs",
"http://*/*",
"https://*/*"
],
"icons":{
"16":"images/icon_16.png",
"128":"images/icon_128.png"
}
}
Background.js有一個調用的函數:
chrome.contextMenus.onClicked.addListener(function(info, tab)
{
... stuff ...
chrome.tabs.sendMessage(tab.id, { action: "showLibraryUI", library: library }, function(response){});
});
在content.js我有監聽功能,但它從未被稱爲:
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse)
{
...stuff...
});
在_generated_background_page.html爲擴展我看到這一點:
端口:無法建立連接。接收結束不存在。 lastError:29 集lastError:29個 dispatchOnDisconnect miscellaneous_bindings:259
我找不到在這裏因此其他職位清單> 2.0的解決方案。
代碼看起來沒問題。你確定代碼的chrome.runtime.onMessage位運行嗎? –
background.js中的所有內容都正常運行。在background.js中我不確定是否chrome.tabs.sendMessage(tab.id,{action:「showLibraryUI」,library:library}正在工作,因爲content.js中的監聽器沒有被調用。 – Lebowski156
@RobW我找到了解決方案:) – Lebowski156