My Chrome extension has the following two javascript files:
background.js:
chrome.tabs.sendMessage(/* tab.id */, { type: MessageType.ON_EXTENSION_INSTALL_OR_UPDATE }, res => {
chrome.tabs.executeScript(/* tab.id */, {
file: script,
});
});
script.js:
chrome.runtime.onMessage.addListener((request, _sender, sendResponse) => {
sendResponse('ok');
});
And get response undefined
back in the content.js, and this error:
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
If I understand the issue, is when the backgeound.js sends the message to the content, the content is not already listen.
Is there a way to make sure the content is ready and listen ?