I\'m developing an extension in Chrome, and there\'s a problem. In my inject.js, I make a request like:
chrome.extension.sendRequest({command:
An HTML background page didn't work for me in Chrome 20.0.1132.57 m on Windows 7 with the same error:
Port error: Could not establish connection. Receiving end does not exist. miscellaneous_bindings:232
I tried using a background.js script with the following content:
chrome.extension.onConnect.addListener(function(port) {
port.onMessage.addListener(function(msg) {
// May be empty.
});
});
That solved the immediate onDisconnect in my content script:
port = chrome.extension.connect();
port.onDisconnect.addListener(function (event) {
// Happened immediately before adding the proper backend setup.
// With proper backend setup, allows to determine the extension being disabled or unloaded.
});
The correct code came from Chromium Extensions messaging example: http://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/extensions/docs/examples/api/messaging/timer/page.js?view=markup
The example also contains the second part that serves as a backend for sendRequest, but I haven't tested it myself:
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
// Don't know if it may be empty or a sendResponse call is required.
});