0
我想消息传递在铬扩展。我按照这个例子(see here) - :铬扩展消息传递没有响应 - 告别:undefined
content_script:
chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
console.log(response.farewell);
});
背景:
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
console.log(response.farewell);
});
});
popup.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
console.log("message recive")
sendResponse({farewell: "goodbye"});
});
虽然我没有复制粘贴 - 消息不发送。错误弹出:
在事件处理误差(未知):类型错误:无法读取的不确定
哪里错财产“告别”?
谢谢,我要阅读 – blueberry