我在异步函数中执行sendMessage
提供的回调时遇到问题。这是我的senario:
popup.js
chrome.runtime.sendMessage('hello from popup', function(res){
alert(res);
});
Background.js
chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
setTimeout(function () {
sendResponse('hi from background');
}, 300);
});
从后台脚本调用的sendResponse
在超时(或任何异步方法)内部不会触发。回调的警报永远不会被执行。在超时之外,它会很好地触发(警报显示响应)。后台脚本控制台或弹出脚本控制台中没有错误。也许这是一个错误?