I am trying to pass a message between my popup to a background page using the one message interface (I’m using code similar to the one in Google’s example for this).
popup:
chrome.extension.sendMessage( {msg: "this is popup's msg"}, function(b){
alert('this is popups callback func' +b.backgroundMsg);
});
and this is how I listen (and reply) in background.js:
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
sendResponse({backgroundMsg: "this is background msg"});
});
Now when I inspect everything in the console the messages are exchanged ok but I get the following error:
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)
Any thoughts?
Copying your code example and filling in the blanks with the manifest and popup structure resulted in a fully working extension without errors. Not sure why you are getting the error that you shared. Try my code and see if you can get rid of the error.
Tips
Example
manifest.json
background.js
popup.html
popup.js
Running Example Screenshots
Clicking extension button with browser window opened to exampley.com
Console log of extension popup
Here is a zip of the files I used http://mikegrace.s3.amazonaws.com/stackoverflow/simple-popup.zip