I'm trying to send an array as a response from a background script to a content script, but it always comes back empty.
This is what I'm trying to do:
content-script
chrome.runtime.sendMessage(urlList, response => {
console.log(response.matchList)
});
background script
chrome.runtime.onMessage.addListener(
(urlList, sender, sendResponse) => {
let matchList = []
urlList.forEach(url => {
chrome.history.search({text: url}, function(results) {
if (results[0]) {
matchList.push(1)
} else {
matchList.push(0)
}
});
});
sendResponse({matchList: matchList});
}
)
It's probably a basic question, but it's my first time trying to build an extension for personal use. My problem is that the history search always happens last, so the array is returned empty.