It appears the response is sent immediately (it logs in the console immediately). Is there a problem with the code or some other issue?
popup.js (browser action)
async function send() {
const response = await chrome.runtime.sendMessage({...});
console.log('response called', response);
}
background.js (service worker)
chrome.runtime.onMessage.addListener(e => onMessage(e));
async function onMessage(message) {
return fetch('https://example.com/')
.then(response => response.json())
.then(response => {
console.log('json called', response);
return response;
})
.catch(error => {
console.log('error called', error);
});
}
Result
response called undefined
json called {...}