Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix 'Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.'

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.

like image 220
Emilio Avatar asked Feb 10 '19 18:02

Emilio


People also ask

How do you solve unchecked runtime Lasterror could not establish connection receiving end does not exist?

The unchecked runtime. lasterror: could not establish connection receiving end does not exist error is fixed by disabling a Chrome extension.


15 Answers

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?

like image 190
frederj Avatar answered Oct 04 '22 07:10

frederj


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"));
});
like image 36
GM GAMER Avatar answered Oct 04 '22 06:10

GM GAMER


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

like image 32
Germanium Corporation Avatar answered Oct 04 '22 08:10

Germanium Corporation


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.

like image 39
kai_onthereal Avatar answered Oct 04 '22 06:10

kai_onthereal


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.

like image 32
David Dehghan Avatar answered Oct 04 '22 08:10

David Dehghan


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
        }
      }
    );
  });
like image 28
Niraj Kumar Avatar answered Oct 04 '22 07:10

Niraj Kumar


🙂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"});
  }
);
like image 21
kia nasirzadeh Avatar answered Oct 04 '22 06:10

kia nasirzadeh


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

like image 41
jeevan Avatar answered Oct 04 '22 07:10

jeevan


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

like image 23
haakon.io Avatar answered Oct 04 '22 08:10

haakon.io


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.

like image 22
Deepinder Avatar answered Oct 04 '22 07:10

Deepinder


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

Disabling the extension fixed the issue.

like image 35
micnguyen Avatar answered Oct 04 '22 08:10

micnguyen


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.

like image 25
krchun Avatar answered Oct 04 '22 06:10

krchun


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)

like image 26
Ryan Avatar answered Oct 04 '22 07:10

Ryan


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.

like image 45
Theodory Avatar answered Oct 04 '22 08:10

Theodory


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

like image 33
Muhammad Azeem Avatar answered Oct 04 '22 06:10

Muhammad Azeem