I'm currently in the process of developing a chrome extension using the node module "chrome-extension-async" and have encountered an issue with utilizing await
within the background listener.
In my setup, the content.js file sends a message to the background script requesting it to perform some asynchronous IO operations:
// content.js
const data = await chrome.runtime.sendMessage({param: ...})
console.log(data)
// background.js
chrome.runtime.onMessage.addListener(async (request, sender,
sendResponse) => {
const result = await performIOOperation();
sendResponse(result);
})
But unfortunately, Chrome throws errors like this:
Uncaught (in promise) Error: The message port closed before a response was received.
I believe there may be a conflict when using async/await within the listener. Does anyone have any insights on resolving this particular issue?