我正在尝试使用一个消息界面在弹出窗口与背景页面之间传递一条消息(我正在使用类似于 Google 示例中的代码)。
弹出窗口:
chrome.extension.sendMessage( {msg: "this is popup's msg"}, function(b){
alert('this is popups callback func' +b.backgroundMsg);
});
这就是我在 background.js 中聆听(和回复)的方式:
chrome.extension.onMessage.addListener(function(msg, sender, sendResponse) {
sendResponse({backgroundMsg: "this is background msg"});
});
现在,当我检查控制台中的所有内容时,消息交换正常,但出现以下错误:
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)
有什么想法吗?