'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.
Solution 1:[1]
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?
Solution 2:[2]
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"));
});
Solution 3:[3]
The error is often caused by a chrome extension. Try disabling all your extensions, the problem should disapear.
Solution 4:[4]
Solution
For Chrome:
You have the window open with the console error, open up a second new window.
In the second window, go to: chrome://extensions
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.
Once you don't have the error, remove the extension.
Solution 5:[5]
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.
Solution 6:[6]
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
}
}
);
});
Solution 7:[7]
Removing 'Udacity Frontend Feedback' chrome extension solved the issue for me.
Solution 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"});
}
);
Solution 9:[9]
This was happening in Chrome for me and I discovered it was McAfee WebAdvisor. Once I disabled it, the message went away:
Solution 10:[10]
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.
Solution 11:[11]
It was tab bnundler for me: https://chrome.google.com/webstore/detail/tab-bundler/ooajenhhhbdbcolenhmmkgmkcocfdahd
Disabling the extension fixed the issue.
Solution 12:[12]
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.
Solution 13:[13]
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.
Solution 14:[14]
in my case removing 'adblocker youtube' extension work for me
Solution 15:[15]
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)
Solution 16:[16]
For me the error was due to the onelogin chrome extension. Removing it fixed the issue.
Solution 17:[17]
Cacher Extension in my case - but yeah disable each and then reload page
Solution 18:[18]
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.
Solution 19:[19]
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/
.
Solution 20:[20]
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:
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.
Solution 21:[21]
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.).
Solution 22:[22]
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
I "achieved" this error after
- installing the Debugger for Chrome extension in Visual Studio Code,
- debugging my code, and
- 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!
Solution 23:[23]
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.
Hope this information helps. Have a great day!
Solution 24:[24]
In my case, I removed the Adblocker Youtube extension in my browser. It solved the problem for me.
Solution 25:[25]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow