Answer the question
In order to leave comments, you need to log in
How to send messages to an additional page?
Tell me how to exchange messages with the extension page. I don't seem to be doing that. Messages come and the response is not, throws out the error Unchecked runtime.lastError: The message port closed before a response was received.
on the background
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if (request.command == "getEventList") {
getEventList().then((eventList) => {
sendResponse({res: 'eventList'});
});
}
}
)
function getEventList(e) {
return new Promise((resolve)=>{
var eventList = new Array();
db.transaction([eventStore], "readonly").objectStore(eventStore).openCursor().onsuccess = function (e) {
var cursor = e.target.result;
if (cursor) {
eventList.push(cursor.value);
cursor.continue();
}
resolve(eventList);
}
})
}
document.addEventListener("DOMContentLoaded", function () {
chrome.runtime.sendMessage({command: "getEventList"}, function(response) {
console.log(response);
});
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question