Unchecked runtime lasterror could not establish connection receiving end does not exist что это
Actual Behavior
Browser starts, active page from last session loads with 3x:
in console log, devtools doesnt show script injection. Reloading fixes it.
Ravenink commented Mar 24, 2022
It happens to me too. I would love to have a solution.
5hanth commented Mar 22, 2022
this can happen if you have two dApps in different tabs with different provider connected
bbelly commented Apr 30, 2022
Any update on this?
Manifest.json
I originally had my content script defined in my manifest and used the MATCHES property to have it load on all URLs. However, I learned that if you try to submit a Chrome extension to the webstore that uses a content script that can run on any URL, it will be subject to a longer review time and higher scrutiny and might get rejected. So the simple solution was just to inject my script manually through message passing.
hamzasharif commented Feb 8, 2022 •
Yes it is, I can replicate this issue on multiple machines. Each with different OS versions (Mac OS).
@kevinghim what kind of info would help with replicating this?
- Close Chrome completely
- Open Chrome
- Navigate to a DApp (an example in the issue description)
- You’ll see an error in the dev console (if you went to the site in the description - If you went to another site just ensure you’re interacting with web3)
lobotomoe commented Apr 14, 2022
Any update on this?
okfirelee commented May 4, 2022
ethereum._state.initialized is a totally temp solution. but everytimes reload the website, this state "ethereum._state.initialized" is false. This issue cannot to work better. I think this issue will be fix.
kevinghim added the Sev2-normal Normal severity; minor loss of service or inconvenience. label May 4, 2022
monsterbitar commented Feb 28, 2022
I've replicated this in firefox on my end. The problem is timing based, if I open my browser and wait for 30s before I go to the first page, I do not get this issue.
My best guess is that there's some point during plugin initialization where if a request is asked of the plugin it has an error due to not being properly initialized but catches that error and prints to the console instead of letting the error propagate.
One solution would be to provide a new function isReady() that provides a promise that resolves only when metamask has finished initializing and is ready to be used, such that web app developers can wait for that promise to resolve before making any requets to metamask.
7 Answers 7
What Chrome docs say is that you can send a message immediately. In the past this would just work and the messages would get either delivered or dropped. But now it is failing.
chrome docs: Upon calling tabs.connect, runtime.connect or runtime.connectNative, a Port is created. This port can immediately be used for sending messages to the other end via postMessage.
So our workaround is to make sure the connection listener is set up first before calling connect() by just delaying the connect() call:
Update: I made a minimum repro extension for this issue.
If you are developing a Chrome extension with message passing, then you might have received the following error: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.. There was some type of behavior change that happened post Chrome 72 that affected the way channels are opened. Essentially, if you try to call runetime.connect() before you have a a channel open, then you will get this error ( Stackoverflow ).
So here’s how I setup Message Passing in my Chrome extension to avoid this error.
Additional context
The text was updated successfully, but these errors were encountered:
j-finance commented Feb 8, 2022
This is also happening to me. I tried uninstalling and reinstalling metamask, but the problem persists.
j-finance commented Feb 8, 2022
Version
Specifications
- Chromium: 87.0.4280.66 and 81.0.4044.83 (Official Build) beta
- TM: v4.12.6121
- OS: W10
The text was updated successfully, but these errors were encountered:
Operating system
derjanb commented Dec 8, 2020
Hmm, my simple test script:
This is working fine here. I always see the console log. However, this is a very simple script, which has no problem with missing "real" document-start . Unfortunately hitting document-start is not possible on browser start, because Chrome is not willing to wait for extensions being initialized. 🤷
So if your userscript needs real document-start (which might be the case since you're using instant injection mode), then I can not fix issues at browser start.
Expected Behavior
Extension works on the first page loaded from last session after browser restart.
Kstar0722 commented Mar 24, 2022
I found temporary solution. the solution is just reload app until ethereum._state.initialized is true
Hardware wallet
Content Script
Remember that the content script runs on the actual webpage that you are on. In this script I listen for a connection and respond to messages:
Setting up my Chrome extension like this allowed me to do message passing without receiving the error: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
I've noticed every time I close Chrome and re-open then go to a page that interacts with the MetaMask extension it breaks the sites integrations.
See the following console output
:
I can consistently replicate this issue. It happens on any site that interacts with MetaMask. Is there a fix or a workaround for this?
Browser
erik0612 commented Mar 20, 2022
Hi Everyone,
Is there any solution for this problem. I tried to reload app until it's initialized. it's working on chrome and firefox. but not working on metamask browser on the phone.
25 Answers 25
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?
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:
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.
I have the same code but still got the error. How do you address "We must ensure that content.js is active" ?
The error is often caused by a chrome extension. Try disabling all your extensions, the problem should disapear.
True for me. I was seeing it with each embedded YouTube iframe, when enabling the extension Youtube Playback Speed Control.
Solution
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.
The core of the problem is that chrome API behavior change and you need add a workaround for it.
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 - 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
Removing 'Udacity Frontend Feedback' chrome extension solved the issue for me.
🙂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.
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:
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.
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.
My chrome extension has the following two javascripts:
background.js , running as background script:
api.js , running as web accessible resource:
When I execute in a tab's console either function (auto-complete knows them, so they are available), I get the error:
Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
and the respone returned is undefined.
I have checked that the id in sendMessage is the same as in the manifest and in the chrome://extensions page, and I have opened the background page DevTools of the extension and manually added the same listener there to make sure the listener is indeed registered.
My searches found that this error means the listener has not been correctly registered, but I don't find the underlying reason. Do you have an idea what causes this error?
Since you're using a web_accessible_resource you must be running it as a page script which doesn't have access to the extension environment - you need to expose messaging via externally_connectable key.
@Atav32, I don't see how your comment relates to the question and my comment so I can't answer it, but I can guess you were not running a page script.
we had the same error and we were not trying to communicate with external extensions. I have a non optimal solution below. Maybe @wOxxOm has a better idea. There is no other api to check if the port is being listened to already before calling connect.
Build type
LJNGDAHL commented Mar 22, 2022
I can confirm that what @monsterbitar describes can also be replicated in Chrome, even when trying out the getting started guide in the MetaMask Docs. Waiting for something like 30s before going to the page works so it definitely seems to be timing based.
Popup Script
Recall that the popup script is the script that is attached to the popup window on your Chrome extension. I first injected my content script to the page once my extension was loaded.
That injects the script then calls my connect function to establish a connection.
This creates a connection for message passing and immediately posts a message to that new connection.
erik0612 commented Mar 24, 2022
I found temporary solution. the solution is just reload app until ethereum._state.initialized is true
yeah, it works for me as well.
raszpl commented Dec 9, 2020
Unfortunately hitting document-start is not possible on browser start, because Chrome is not willing to wait for extensions being initialized.
Thats what I was afraid of :( I havent seen this documented/mentioned anywhere on the web.
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
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.
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.
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
Error messages or log output
Steps to reproduce
raszpl commented Nov 29, 2020 •
Steps to reproduce:
settings/on startup/Continue where you left off
install TM: v4.12.6121, injection mode: instant
load random website, restart browser
ctrl-shift-i to open inspector, look at console:
extensions seem to have worked and got injected, but injection mode: instant failed and website was loaded before any scripts had a change to start running. This seems to affect all extensions? as I have one modifying some headers thru chrome.webRequest.onBeforeSendHeaders and that also fails to fire up fast enough on the very first website loaded from previous session (Continue where you left off) in Chrome. Im starting to suspect it might be Googles misguided fight against synchronous code paths (manifest V3 killing blocking webRequest, now delayed "run_at": "document_start") in chase for faster page loads - they recently boasted about "optimizations" reducing first page load times.
Читайте также: