Chrome Extension “Receiving end does not exist.”

Chrome Extension “Receiving end does not exist.”

I have personally spent a tremendous amount of time investigating this problem. Let's see why it's trickier than it seems like.

There are actually three main points what could go wrong if you're facing this problem with your extensions:

Not following the official API

Google writes pretty decent tutorials and explanations, so I won't be copywriting it. This article is a great showcase of what and in what cases you should be doing to make a chat between your scripts. The hints:

  • How to send a message (sendMessage). Live example in PopUpOFF content script.
  • How to handle it - get and process (onMessage). Example from background.js.
  • Don't use 'chrome.extension.sendRequest || .onRequest' or 'chrome.extension.sendMessage || .onMessage' if you don't need to support the Chrome oldest versions. You most likely don't.

You know it all well already? Still doesn't work?

You must've messed scripts up.

Make sure your background/content scripts are updated, loaded (reloaded) and available to each other at the very same moment you're trying to pass a message. Try incognito mode, disable all other extensions, go get some cofeewater. If you're pretty sure you did everything right, but it's not working anyway - take counsel of one's pillow.

It is working, but the error keeps randomly appearing? Why didn't you tell me at the start? Let's go see why:

Browser getting you there

Every time you update the dev version of your extension, Chrome, or whatever browser you use, starts to use the newest version of your scripts on the opened pages (if you interact with any) but content scripts are kept from the previous "version". They are not updating automatically (you most likely set the property "run_at": "document_end", so don't blame the browser). So, technically, you're trying to reach the not injected (yet!) content script from the new version - but there is no (because you didn't load the page after the extensions update), so the browser throws an error. But it can work just as well because your new script can be identical to the old one.

What to do then? Basically, you can track if an old connection is not needed and disable it or manually update your scripts. I'm going to write an article about it later.

If your content script in production is updating only with the extension itself, it should not be a problem. But now you know why you're getting this error during the development and not in production.

Thank you for attention and have a great life now. See ya!

To main page