I have an App page (extension_id://app.html) I want to create a new tab:
JavaScript
x
3
1
let tab = await chrome.tabs.create({ url: candidate_url });
2
chrome.tabs.sendMessage(tab['id'], {"message": "sendMessage", "data": {}, "tabID": tab['id']});
3
however, when I send a message to this tab id it doesnt work.
here is the content.js script, but it doesn’t alert or console log
JavaScript
1
9
1
chrome.runtime.onMessage.addListener(
2
async function(request, sender, sendResponse) {
3
if( request.message === "sendMessage"){
4
console.log("XX");
5
alert("XX");
6
}
7
}
8
);
9
Advertisement
Answer
adding a setTimeout to call the send function works correctly, just have to have the page load and timer called perfectly, about 8 to 10 seconds is enough time for the page to load.
TIA