146

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
  • 5,609
  • 7
  • 39
  • 61
Emilio
  • 1,814
  • 3
  • 9
  • 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
  • 2
    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

28 Answers28

97

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,483
  • 9
  • 20
  • 4
    worked for me by disabling `Run JavaScript` extension. thanks. – Asef Hossini Aug 13 '21 at 09:24
  • 1
    There are some extension that occurs this issue. So you use find that extension by disable all and enable one by one. In my case, "writer" extension was the problem. – Gabriel Aoki Nov 24 '22 at 02:15
75

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
  • 851
  • 5
  • 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
  • 36
    this is the only answer that makes some technical sense to a developer :( – Deepak Mar 02 '20 at 08:50
  • 7
    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
  • 1
    If I get correctly its syaing refresh the tab you are sending – Charalamm Aug 22 '21 at 13:14
36

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

  • 2
    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
  • This is not a real solution to the core problem. People use multiple Chrome Extensions. Disabling a bunch of them might solve this bug for *us* in particular -- and we might get the Chrome Extension to work properly for us -- but users that continue to use all of their Chrome Extensions will continue to encounter the error and won't get the correct functionality of the Chrome Extension we're trying to build. – king_anton Mar 11 '23 at 05:51
36

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
  • 369
  • 2
  • 6
18

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
  • 22,159
  • 10
  • 107
  • 95
16

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
  • 743
  • 12
  • 24
  • 6
    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
  • 2
    @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
10

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"});
  }
);
8

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

jeevan
  • 161
  • 2
  • 8
6

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
  • 477
  • 6
  • 19
4

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
  • 41
  • 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
  • 1
    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
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,419
  • 18
  • 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

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,728
  • 5
  • 31
  • 43
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
  • 994
  • 1
  • 9
  • 19
1

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
  • 576
  • 11
  • 23
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
  • 301
  • 1
  • 3
  • 12
1

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

1

I also encountered this problem when I was developing chrome extensions.

Error: Could not establish connection. Receiving end does not exist.

The error message from chrome.tabs.sendMessage

The solution is to make it return the promise and use catch to handle the error and define it yourself. Example

Carson
  • 6,105
  • 2
  • 37
  • 45
0

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

Bitclaw
  • 813
  • 9
  • 8
0

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

konik
  • 173
  • 1
  • 2
  • 8
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
  • 159,648
  • 54
  • 349
  • 530
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
  • 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,760
  • 2
  • 11
  • 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
  • 5,609
  • 7
  • 39
  • 61
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

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

nilknow
  • 319
  • 3
  • 6
0

I solved this in following way. This is mainly chrome extension problem, try to first empty cache and hard reload for this inspect any window and hold reload button about 2 second then it will appear 3 options click last one which is mentioned above then go to manage extensions and turn off one by one and then turn on again one by one and check it's gone or not.

Ruhul Amin
  • 29
  • 6
-1

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

chrome.runtime.lastError

It's an error that appear in the Chrome devTools console. And it's related to Chrome Chrome Message Passing

Because of the 'rigid structure' of the Chrome platform, it's not easy to pass data between different Chrome windows/tabs, as it's common to do in the 'object oriented' programming languages.

In Chrome extensions, usually, there is not a single file of code, that runs for all pages or tabs.

It's a common use, to build many different files of code in javascript, for different Windows/tabs/url address.

So, when the software, need to pass data from different windows/tabs/url, it's made using 'message passing'

The 'message passing', allow to send a 'message' and wait to receive a message as 'callBack'

But sometimes happens, in example, that the url of a window, or a tab, change, when there is a 'message passing' function which has been triggered, but still not returned.

If this situation it's not managed by code (as wrote TechDogLover OR kiaNasirzadeh), or it's an old extension not updated, this error can arise.

So as others users said, it could be an extension, which is running in your Chrome.

But if your window doesn't crash, it doesn't have much sense disable an extension because of such message appear in the devTools Console.

And it doesn't have sense try to understand how to fix it (if you are not the developer of the software which is causing the error), because the variables are so many, that it's not said that the error will be triggered again, in the same situation.

In those cases, in my opinion, if you really want to do something, a good thing to do could be, once you find the extension that cause the error, contact the extension developer and report it.

And if you are the developer, you could check for a missing

if(!chrome.runtime.lastError){
    // here if there is no error
} else {
    // here if there is an error
}

Or, also you could check your code, if you did more than one callBack, e.g. as explained there wOxxOm comment

Marcello
  • 438
  • 5
  • 21
-2

Apparently an error occurred during browser startup and the browser did not launch extensions such as stylish, adblock. I closed the browser and reopened it and my page worked without errors.

Bahurtsev
  • 1
  • 1