Due to some of the changes in MV3, I now need to check if the content script is running on a tab because the content scripts are no longer automatically loaded on the tabs on the update or install event.
To do this, I'm using the messaging feature in the Tabs API. I send the tab and a message and the content script has a listener to send a response of true. If the service worker gets a response of true, it knows that the content script is running. If it gets a response of undefined, it knows that the content script needs to be executed on the page.
This is working.
The only issue/improvement is I don't want the "
Could not establish connection. Receiving end does not exist." error message to be logged in the console. Is there a way to somehow catch this error?
In fact, that would improve my current process if I was able to catch that error because then I wouldn't need the content script to respond at all. I could just execute the script on the tab if I get this error, as that means there's no listener on that tab.