How to stop "Could not establish connection. Receiving end does not exist." from printing in logs

17,151 views
Skip to first unread message

ComputerWhiz

unread,
Feb 4, 2022, 11:56:37 AM2/4/22
to Chromium Extensions
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.

hrg...@gmail.com

unread,
Feb 4, 2022, 12:04:50 PM2/4/22
to Chromium Extensions, ComputerWhiz
Try adding this line right after you receive the response:
chrome.runtime.lastError ;

ComputerWhiz

unread,
Feb 4, 2022, 12:56:58 PM2/4/22
to Chromium Extensions, hrg...@gmail.com, ComputerWhiz
That works. Thanks!

Simeon Vincent

unread,
Feb 4, 2022, 6:41:07 PM2/4/22
to ComputerWhiz, Chromium Extensions, hrg...@gmail.com
ComputerWhiz, can you clarify what you mean by "the content scripts are no longer automatically loaded on the tabs on the update or install event"?

To my knowledge Chrome has never injected the static content scripts registered in manifest.json into open tabs on install or update. Rather, the content script will be injected the next time the user navigates to a matching page.

Simeon - @dotproto
Chrome Extensions DevRel


On Fri, Feb 4, 2022 at 9:57 AM ComputerWhiz <hello.wes...@gmail.com> wrote:
That works. Thanks!

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/2b7e38e3-8d6e-47f9-9040-c5bf6f2237d3n%40chromium.org.

ComputerWhiz

unread,
Feb 4, 2022, 9:54:43 PM2/4/22
to Chromium Extensions, Simeon Vincent, Chromium Extensions, hrg...@gmail.com, ComputerWhiz
Now that you mention it, you're right. That's never been the default behavior in Chrome. It looks like a Firefox-specific behavior.
Reply all
Reply to author
Forward
0 new messages