metamask-extension icon indicating copy to clipboard operation
metamask-extension copied to clipboard

[Bug]: Breaking DApps - Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

Open hamzasharif opened this issue 4 years ago • 20 comments

Describe the bug

Hey there,

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 Screenshot 2022-01-28 at 21 24 30 :

I can consistently replicate this issue. It happens on any site that interacts with MetaMask. Is there a fix or a workaround for this?

Steps to reproduce

Setup:

  • Mac OS - Tried on many different machines with different OS versions e.g. 12.1
  • Chrome Browser - Different versions e.g. Version 97.0.4692.99 (Official Build) (x86_64)
  1. Close Chrome
  2. Re-open Chrome
  3. Once the browser has opened, go to any site/dapp that interacts with MetaMask e.g. https://nftcontracts.art/arcadelife
  4. Check the developer console for error messages

Error messages or log output

Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
contentscript.js:1 MetaMask: Content script lost connection to "MetaMask Background Multiplex". undefined
contentscript.js:1 MetaMask: Muxed traffic for channel "metamask-provider" failed. undefined
contentscript.js:1 MetaMask: Content script lost connection to "MetaMask Background Legacy Multiplex". undefined
contentscript.js:1 MetaMask: Muxed traffic between channels "provider" and "metamask-provider" failed. undefined
contentscript.js:1 MetaMask: Muxed traffic for channel "publicConfig" failed. undefined

Version

10.8.1

Build type

No response

Browser

Chrome

Operating system

MacOS

Hardware wallet

No response

Additional context

No response

hamzasharif avatar Jan 29 '22 02:01 hamzasharif

@hamzasharif tried reproducing using the same OS/Browser combo, and not getting the same errors. Can you provide more details.

kevinghim avatar Feb 07 '22 19:02 kevinghim

This is also happening to me. I tried uninstalling and reinstalling metamask, but the problem persists.

j-finance avatar Feb 08 '22 19:02 j-finance

Related? https://github.com/MetaMask/metamask-extension/issues/9407

j-finance avatar Feb 08 '22 19:02 j-finance

Related? #9407

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?

  1. Close Chrome completely
  2. Open Chrome
  3. Navigate to a DApp (an example in the issue description)
  4. 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)

Thank you!

hamzasharif avatar Feb 08 '22 23:02 hamzasharif

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.

monsterbitar avatar Feb 28 '22 07:02 monsterbitar

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.

erik0612 avatar Mar 20 '22 15:03 erik0612

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.

LJNGDAHL avatar Mar 22 '22 14:03 LJNGDAHL

this can happen if you have two dApps in different tabs with different provider connected

5hanth avatar Mar 22 '22 15:03 5hanth

It happens to me too. I would love to have a solution.

Ravenink avatar Mar 24 '22 15:03 Ravenink

I found temporary solution. the solution is just reload app until ethereum._state.initialized is true

Kstar0722 avatar Mar 24 '22 15:03 Kstar0722

I found temporary solution. the solution is just reload app until ethereum._state.initialized is true

yeah, it works for me as well.

erik0612 avatar Mar 24 '22 15:03 erik0612

Any update on this?

lobotomoe avatar Apr 14 '22 06:04 lobotomoe

Any update on this?

bbelly avatar Apr 30 '22 08:04 bbelly

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.

basemain avatar May 04 '22 17:05 basemain

Any news?

axell9641 avatar Jun 10 '22 17:06 axell9641

Hey there, is there any news on this?

Since today, my MetaMask (Firefox extension) shows a completely blank screen (both popup and home.html)

And any tab opened display those errors in the console:

MetaMask: Content script lost connection to "MetaMask Background Multiplex". undefined MetaMask: Muxed traffic for channel "metamask-provider" failed. undefined MetaMask: Content script lost connection to "MetaMask Background Legacy Multiplex". undefined MetaMask: Muxed traffic between channels "provider" and "metamask-provider" failed. undefined MetaMask: Muxed traffic for channel "publicConfig" failed. undefined

dievardump avatar Jun 28 '22 11:06 dievardump

I am also able to reproduce this issue on Firefox and Chromium based browsers with the MetaMask extension.

When closing out of the browser completely (tabs and all), and reopening directly to a dApp (say you selected the link from discord, or are testing in a local dev environment which opens the browser to that page for you), MetaMask will consistently throw the above errors and will not work until you refresh the page.

This problem exists not only on my dApps, but very popular ones as well such as UniSwap.

This is quite a breaking issue for front-end developers trying to create a smooth experience for users. An option to refresh the page once MetaMask has loaded or have a function IsReady() as someone has suggested above would definitely help with this issue.

Dope-Ass-Ninja avatar Aug 11 '22 19:08 Dope-Ass-Ninja

I solved that issue using this code. var timerID = setInterval(function() { if (document. readyState === 'complete') { if (ethereum._state.initialized == true) { clearInterval(timerID); } else { location.href = location.href; } } }, 1000);

AgreenCabTree avatar Aug 12 '22 16:08 AgreenCabTree

This issue has been automatically marked as stale because it has not had recent activity in the last 30 days. It will be closed in 60 days. Thank you for your contributions.

github-actions[bot] avatar Jun 13 '25 00:06 github-actions[bot]

This issue was closed because there has been no follow activity in 90 days. If you feel this was closed in error please provide evidence on the current production app in a new issue or comment in the existing issue to a maintainer. Thank you for your contributions.

github-actions[bot] avatar Aug 13 '25 00:08 github-actions[bot]