I am having an issue executing the callback supplied by sendMessage
, within an asynchronous function. Here is my 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);
});
The sendResponse
called from the background script, does not fire when its inside the timeout (or any asynchronous method). The callback's alert never gets executed. Outside of the timeout, it fires just fine (the alert shows the response). There are no errors in the background scripts console, or in the popup scripts console. Perhaps this is a bug?