Quando si cerca di comunicare tra il mio script di Content e sfondo che ricevo i seguenti errori:Chrome Extension: errore porta: impossibile stabilire una connessione. La fine di ricezione non esiste.
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);
});
}
e il mio manifest.jso 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"]
}
]
}
ho trovato la soluzione per aggiungere un BACKGROUND_PAGE: "background.html" con una background.html vuoto, ma poiché BACKGROUND_PAGE non è supportato dal manifest_version: 2, non posso usare quella.
Un altro modo, che risolvono il mio problema con esattamente lo stesso errore: http://stackoverflow.com/a/13565529/390747 – WooCaSh