Khi cố gắng để giao tiếp giữa trang nội dung và Bối cảnh của tôi Script tôi nhận được các lỗi sau đây:Tiện ích mở rộng của Chrome: Lỗi cổng: Không thể thiết lập kết nối. Kết thúc nhận không tồn tại.
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);
});
}
và số manifest.jso của tôi n
{
"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"]
}
]
}
tôi tìm thấy giải pháp cho thêm một BACKGROUND_PAGE: "background.html" với một background.html trống rỗng, nhưng kể từ khi BACKGROUND_PAGE không được hỗ trợ từ manifest_version: 2, tôi không thể sử dụng.
Một cách khác, trong đó giải quyết vấn đề của tôi với chính xác lỗi này giống nhau: http://stackoverflow.com/a/13565529/390747 – WooCaSh