In my eventPage.js(background, persistent=false):
chrome.runtime.onMessage.addListener(async function(request, sender, sendResponse) {
await new Promise((resolve, reject) => {
chrome.downloads.search({id: files[i]}, function (item) {
sendfiles.push(item[0].id);
resolve();
});
});
console.log(sendfiles); // contains (item[0].id), means it did wait.
sendResponse("hello"); // Should send hello back
return true;
});
And in my popup.js:
chrome.runtime.sendMessage("",(response) => {
alert(response); // alerts undefinded instead of hello
});
My error:
Unchecked runtime.lastError: The message port closed before a response was received.
As written in the comments of the code, It should respond to the request from the popup.js with "hello", but because it waited in the Promise, I get the error and the response becomes undefinded before I can sendResponse my "hello" (I'm guessing this is what happening)..