當嘗試,我得到了下面的錯誤我的內容 - 與後臺腳本之間的通信:Chrome擴展程序:端口錯誤:無法建立連接。接收結束不存在。
Port error: Could not establish connection. Receiving end does not exist.
Error in event handler for 'undefined': Cannot read property 'message' of undefined
TypeError: Cannot read property 'message' of undefined
background.js
function onRequest(request, sender, callbackFunction) {
console.log("Me (BS) became this Message:" + request.message);
sendResponse({message: request.message})
};
chrome.extension.onRequest.addListener(onRequest);
streamcloud.js
function contactBackground(nachricht){
chrome.extension.sendMessage({message: nachricht}, function(response) {
console.log("The Background Script got the following Message: " + response.message);
});
}
和我的manifest.jso ñ
{
"name": "InstantWatch - Dev",
"manifest_version": 2,
"version": "0.7",
"permissions": ["tabs", "http://*/", "https://*/"],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_title": "InstantWatch",
"default_icon" : "icon.ico"
},
"content_scripts": [
{
"matches": ["http://*/*", "http://*/*"],
"js": ["jquery.js", "streamcloud.js"]
}
]
}
我找到了解決方案添加BACKGROUND_PAGE:用空background.html「background.html」,但由於BACKGROUND_PAGE因爲manifest_version不支持:2,我不能使用。
的另一種方式,它解決我的問題,正是這個同樣的錯誤: http://stackoverflow.com/a/13565529/390747 – WooCaSh 2012-11-26 13:11:58