Thank you for your quick response, Juraj.
The documentation says: “Extensions cannot send messages to content scripts using this method. To send messages to content scripts, use tabs.sendMessage.”
I tried the following:
const requestFilter = {
tabId: -1,
types: ['main_frame'],
urls: ['http://*/*', 'https://*/*'],
};
browser.webRequest.onCompleted.addListener(
sendMessageToSidebar, // function
requestFilter
);
function sendMessageToSidebar() {
browser.tabs.sendMessage({ action: 'injectCSS', data: targetUrl });
}
but I got an error saying that the receiving end didn’t exist, so it seems that the message is sent before the content script is injected in the sidebar panel. Mind you, I’m not sure that I can send a message this way without specifying a tabId.
I ended up using your hack instead and it’s working very well. Thank you, again!