My content script sends a message to background.js. In the callback handler for response, I had the last line as "alert(alrt_msg)"
. Upon executing code, I get the alert box, but after clicking "OK", the chrome console shows following in red:
Error in event handler for 'undefined': Cannot call method 'disconnect' of null TypeError: Cannot call method 'disconnect' of null
at chromeHidden.Port.sendMessageImpl (miscellaneous_bindings:285:14)
at chrome.Event.dispatch (event_bindings:237:41)
at Object.chromeHidden.Port.dispatchOnMessage (miscellaneous_bindings:250:22)
Its not much informative but intuitively I knew that this error is because some structure somewhere is garbage collected while user clicks on "OK". So I put my code as
window.setTimeout(function() { alert(alrt_msg); } , 1);
This made it work without above error. Still, after searching for documentation or google, I was not able to find the exact reason behind this. Can someone please explain whats going on and if documentation contains a specific way to do this?
I have came to the same issue. This is due to an error (my code's fault) in a function which is called in the response handler.
Here is my code:
In background.js - the listening side
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var update_msg = 'test';
sendResponse({data: update_msg});
return false; // -> Add this or not add this do not matter
});
}
On the sending side:
function updateObjDatabase(obj) {
chrome.runtime.sendMessage({data: obj}, function(response) {
// Update when it's done
update_msg_handler(response.data);
});
}
function update_msg_handler(msg) {
..... error code here
}
The wrong code is actually in the function update_msg_handler
. But the Chrome console just won't tell you that details. You have to add some console.log to debug if you don't have an IDE.
I had same error. It was iMacros app. After I deleted it no error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With