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