122

I have the following error in the Chrome Dev Tools console on every page-load of my Node/Express/React application:

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist

This error makes a reference to localhost/:1. When I hover over this, it shows http://localhost:3000/, the address I'm viewing the app at in the browser.

Anyone have an idea what is going on? Most of the other threads I've found that bring up this error seem to be related to someone trying to develop a Chrome Extension, and even then they tend to have very few responses.

Super Jade
  • 4,413
  • 5
  • 31
  • 50
Emilio
  • 1,536
  • 3
  • 8
  • 11
  • 2
    You can see my solution on a dupe this question. https://stackoverflow.com/questions/54181734/chrome-extension-message-passing-unchecked-runtime-lasterror-could-not-establi/54686484#54686484 – David Dehghan Feb 14 '19 at 09:04
  • 1
    The answers to this question are all of the kind "It wasn't caused by my code. I had to disable XY extension". If you are looking for a solution from a developer's perspective, see the linked Q&A above. – Martin Schneider Sep 19 '20 at 11:04
  • What solved my problem was closing Chrome and opening it again. The server was running during this process. I guess refreshing the page also works fine – Charalamm Nov 09 '20 at 14:51

25 Answers25

88

I'd been getting the exact same error (except my app has no back-end and React front-end), and I discovered that it wasn't coming from my app, it was actually coming from the "Video Speed Controller" Chrome extension. If you aren't using that extension, try disabling all of your extensions and then turning them back on one-by-one?

frederj
  • 1,323
  • 8
  • 20
53

I found the same problem when developing the Chrome extensions. I finally found the key problem.

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist

The key problem is that when background.js sends a message to the active tab via chrome.tabs.sendMessage, the content.js on the page is not ready or not reloaded. When debugging. We must ensure that content.js is active. And it cannot be a page without refreshing , The old pages don not update you js itself

Here is my code:

//background.js
chrome.tabs.query({active: true, currentWindow: true},function(tabs) {
  chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
      console.log(response);
  });
}); 


//content.js
chrome.runtime.onMessage.addListener(function(request, sender, sendResponse){
    console.log(request, sender, sendResponse);
    sendResponse('我收到你的消息了:'+JSON.stringify("request"));
});
GM GAMER
  • 631
  • 4
  • 5
  • 2
    In the above example, sendResponse was called synchronously. If you want to asynchronously use sendResponse, add return true; to the onMessage event handler. So, you right. – MeirDayan Feb 29 '20 at 12:40
  • 26
    this is the only answer that makes some technical sense to a developer :( – Deepak Mar 02 '20 at 08:50
  • 2
    I have the same code but still got the error. How do you address "We must ensure that content.js is active" ? – neiya Dec 02 '20 at 20:15
  • If I get correctly its syaing refresh the tab you are sending – Charalamm Aug 22 '21 at 13:14
38

The error is often caused by a chrome extension. Try disabling all your extensions, the problem should disapear.

  • 1
    True for me. I was seeing it with each embedded YouTube iframe, when enabling the extension Youtube Playback Speed Control. – Bob Stein Aug 11 '19 at 03:04
33

Solution

For Chrome:

  1. You have the window open with the console error, open up a second new window.

  2. In the second window, go to: chrome://extensions

  3. Disable each extension by toggling (the blue slider on the bottom right of each card), and refresh the window with the console after toggling each extension.

  4. Once you don't have the error, remove the extension.

kai_onthereal
  • 340
  • 2
  • 6
16

If you are an extension developer see this Chrome Extension message passing: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist

The core of the problem is that chrome API behavior change and you need add a workaround for it.

David Dehghan
  • 18,323
  • 7
  • 100
  • 88
14

You need to handle window.chrome.runtime.lastError in the runtime.sendMessage callback. This error just needs to be handled. Below is my code:

window.chrome.runtime.sendMessage(
      EXTENSION_ID,
      { message:"---" }, // jsonable message
      (result) => {
        if (!window.chrome.runtime.lastError) {
           // message processing code goes here
        } else {
          // error handling code goes here
        }
      }
    );
  });
Niraj Kumar
  • 723
  • 11
  • 23
  • 3
    It looks like you are hiding the error instead of fixing it. When I received that error, it meant the message was not received and instead I received an empty response. – mFritz May 27 '21 at 17:58
  • 1
    @mFritz - the reason, you are getting an empty response is because, either the extension is not available or it is not responding to messages due to some error. I am not hiding the error. You can create and use the else block if you need to handle the error – Niraj Kumar May 28 '21 at 03:47
9

Removing 'Udacity Frontend Feedback' chrome extension solved the issue for me.

jeevan
  • 163
  • 2
  • 8
8

simple answer:

if you have no response from another End it will also tell you Receiving end does not exist.

detailed answer:

if you have no answer from another end it will also tell you Receiving end does not exist. so if you have any callBack function which should use response in your .sendMessage part, you should either delete it or handle it if you probably have no response from another side.

so

if i wanted to re-write Simple one-time requests section of Message passing documents of google API i will write it with error handlers for callback functions in message-sending methods like this:

Sending a request from a content script looks like this:

chrome.runtime.sendMessage({greeting: "hello"}, function (response) {
    if (!chrome.runtime.lastError) {
        // if you have any response
    } else {
        // if you don't have any response it's ok but you should actually handle
        // it and we are doing this when we are examining chrome.runtime.lastError
    }
});

Sending a request from the extension to a content script looks very similar, except that you need to specify which tab to send it to. This example demonstrates sending a message to the content script in the selected tab.

chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
  chrome.tabs.sendMessage(tabs[0].id, {greeting: "hello"}, function(response) {
    if (!chrome.runtime.lastError) {
        // if you have any response
    } else {
        // if you don't have any response it's ok but you should actually handle
        // it and we are doing this when we are examining chrome.runtime.lastError
    }
  });
});

On the receiving end, you need to set up an runtime.onMessage event listener to handle the message. This looks the same from a content script or extension page.

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    console.log(sender.tab ?
                "from a content script:" + sender.tab.url :
                "from the extension");
    if (request.greeting === "hello")
      sendResponse({farewell: "goodbye"});
  }
);
kia nasirzadeh
  • 2,518
  • 20
  • 26
5

This was happening in Chrome for me and I discovered it was McAfee WebAdvisor. Once I disabled it, the message went away: enter image description here

haakon.io
  • 467
  • 6
  • 18
3

I removed "Video Speed Controller" Chrome Extension and the error was removed. It worked for me like this. In your case there may be some other extensions too which may cause this error.

Deepinder
  • 31
  • 3
2

It was tab bnundler for me: https://chrome.google.com/webstore/detail/tab-bundler/ooajenhhhbdbcolenhmmkgmkcocfdahd

Disabling the extension fixed the issue.

micnguyen
  • 1,289
  • 17
  • 25
  • Same for me, tab bundler extension... if using edge, it displays the unique ID of the extension and thus you can find it and disable it instead of going on a one by one basis as other answers suggest. – 1vand1ng0 Jun 06 '20 at 23:41
2

Oddly enough, for myself I simply disabled all my extensions and the error went away.

However, after re-enabling all of the ones I disabled, the error was still gone.

krchun
  • 874
  • 1
  • 8
  • 18
1

This is caused simply by installed chrome extensions, so fix this first disable all chrome extensions then start to enable one after another to detect which extension is cause you can enable the remaining.

Theodory
  • 89
  • 2
  • 10
1

in my case removing 'adblocker youtube' extension work for me

1

The simple fix is to return true; from within the function that handles chrome.tabs.sendMessage. It's stated here.

(this is similar to other answers)

Ryan
  • 11
  • 1
  • 1
    OP mentioned that they are not developing a Chrome extension. This response is not relevant to OP. – Dawson B Apr 27 '22 at 05:28
  • Response is relevant to the issue, regardless of the OPs use, and therefore should help them understand what exactly is causing the issue. This could also be passed from the OP to the maintainer of the extension OP is using, by the OP, in order to properly resolve the issue. Thanks. :) – Ryan Apr 28 '22 at 13:46
0

For me the error was due to the onelogin chrome extension. Removing it fixed the issue.

Bitclaw
  • 805
  • 9
  • 8
0

Cacher Extension in my case - but yeah disable each and then reload page

konik
  • 83
  • 1
  • 1
  • 7
0

It was a few extensions for me. Disabling and then re-enabling fixed the problem though. Grammarly was one of them. Hope the errors don't return.

Eliezer Steinbock
  • 4,135
  • 4
  • 25
  • 39
0

I was testing my extension on edge://extensions/ page/tab. Testing it on another tab solved this issue. I think this may also occur for chrome://extensions/.

bantya
  • 530
  • 12
  • 23
0

This is usually caused by an extension.

If you don't want to disable or remove the extension which causes this error, you can filter out this specific error by typing -/^Unchecked\sruntime\.lastError\:\sCould\snot\sestablish\sconnection\.\sReceiving\send\sdoes\snot\sexist\.$/ in the Filter box in the console:

Example

Example #2

As far as I've seen, this filter will stay until you remove it manually, you can close and reopen the console, restart Chrome, etc as much as you want and the filter will never be removed automatically.

Brad
  • 152,561
  • 47
  • 332
  • 504
Donald Duck
  • 7,638
  • 19
  • 69
  • 90
  • Fine, but what does it actually mean? – Brad Mar 20 '20 at 01:13
  • @Brad What does what mean? The regex? It simply filters out errors with the text `Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist`. – Donald Duck Mar 25 '20 at 10:20
0

I get the message only on the first Chrome page =
When Chrome is not running, and I open it - either directly or by double-clicking on a page on my desktop.
(I don't know if this matters, but I have "Continue running background apps when Google Chrome is closed" off.)
So, I'm assuming it's Chrome's crap spying/"enhancing user experience" attempt.
I don't know what it's trying to send, but I'm glad it's not able to! :)
So, second (or any but first) tab has no error.
== No need to disable anything (extensions, etc.).

iAmOren
  • 2,638
  • 2
  • 10
  • 23
0

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.


I "achieved" this error after

  1. installing the Debugger for Chrome extension in Visual Studio Code,
  2. debugging my code, and
  3. closing and reopening the non-debugging Chrome window. (I had left Chrome running my app while debugging.)

Solutions:

  • Stop using the extension.
  • Refresh the non-debugging Chrome window.
  • Use a different debugger.

Of course, the console error reappears when I redo steps 2 and 3 above with the Debugger for Chrome. This encourages me to use other debuggers instead. Then I don't mistakenly think my own code produced the console errors!

Super Jade
  • 4,413
  • 5
  • 31
  • 50
0

For me this was caused by :

Iobit Surfing Protection & Ads Removal extension

which comes with Iobit advanced system care software. However, the console might provide you with relevant information on what you need do disable or the cause for that problem.

The likely cause of this error, as per google searches is because that extension which causes the error, might be using the chrome.runtime.sendMessage() and then tries to use the response callback.

Error shown in the console

Hope this information helps. Have a great day!

0

In my case, I removed the Adblocker Youtube extension in my browser. It solved the problem for me.

Volem
  • 598
  • 2
  • 14
MAM.AASIM
  • 11
  • 2
0

For chrome extension development, it's an error thrown by chrome.tabs.sendMessage method.

Here is the link of related documentation: https://developer.chrome.com/docs/extensions/reference/tabs/#method-sendMessage. In the link you can find the description for the callback function: If an error occurs while connecting to the specified tab, the callback is called with no arguments and runtime.lastError is set to the error message.

According to documentation above, the error is because of the specified tab. I restart chrome and reloaded the extension, and this issue is fixed

poorguy
  • 179
  • 2
  • 4