So I have been trying for hours, but I could not make it work. This is happening only on a published chrome extension not on my unpacked build
this is the pop-up script:
_handleMessageResponse = (response) => {
console.log(response) // undefined
};
chrome.runtime.sendMessage(
"message",
this._handleMessageResponse
);
and on my background script
chrome.runtime.onMessage.addListener(
async (
message,
_sender: any,
sendResponse: any
) => {
try {
const response = await someAsyncApiCall();
console.log(response) // {some: 'prop'}
sendResponse({
response
});
return true;
} catch (e) {
sendResponse({ errorMessage: e.message });
return true;
}
}
);
In my local environment it returns an object, while in a published extension returns undefined. In the published extension the response in the background script is of course defined.
Probably is because is an async function, but I did not find anything rather then returning true from the handler, but even that (like in my code is showing) it did not working.