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

Unchecked runtime.lastError: Could not establish connection

Open birdca opened this issue 6 years ago • 38 comments

Describe the bug When running the test-dapp that metamask doc provided, it'll show "Unchecked runtime.lastError: Could not establish connection", and keep displaying "Sending metamask: reload message".

To Reproduce (REQUIRED) Steps to reproduce the behavior, libraries used with version number, and/or any setup information to easily reproduce:

  1. Go to chrome://extensions/
  2. Disable MetaMask
  3. Switch back to test-dapp
  4. Reload
  5. Click on "INSTALL METAMASK" button, it'll redirect to chrome://extensions/ in a new tab
  6. Click on "Enable" on chrome://extensions/
  7. After extensions reload complete, test-dapp starts to reload, wait for 1-2 seconds when test-dapp is still reloading, switch back to test-dapp
  8. the "CONNECT" button didn't work and see errors on console

Expected behavior The "CONNECT" button suppose to work after enable MetaMask on chrome://extensions/

Screenshots If applicable, add screenshots to help explain your problem. Image of Issue [NOTE]: The clear version of video is here

Browser details (please complete the following information):

  • OS: OS X
  • Browser Chrome Version 85.0.4183.102 (Official Build) (64-bit)
  • MetaMask Version 8.0.8

Additional context (Error Messages, etc.) Add any other context about the problem here.

birdca avatar Sep 15 '20 08:09 birdca

I've found another scenario to reproduce the error "Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist."

  1. Make sure Chrome is closed (metamask is installed on chrome)
  2. Double click on a link to a dapp (for example https://web3examples.com/ethereum/web3js_browser/version.html)
  3. Now chrome starts and in the development console you see the error message: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

It seems to be a timing issue, see also: https://stackoverflow.com/questions/54181734/chrome-extension-message-passing-unchecked-runtime-lasterror-could-not-establi

OS: Windows 10 Browser: Version 87.0.4280.66 (Official Build) (64-bit) Metamask: 8.1.3

gpersoon avatar Nov 24 '20 09:11 gpersoon

As of MetaMask v9.0.2 and Chrome 88.0.4324.96, I was not able to reproduce this behavior. Reading the aforementioned Stackoverflow thread seems promising in suspecting a Chrome bug that may or may not have been fixed, I was not able to find a related Chrome bug on their issue tracker. On our end there definitely could be improvements on our message passing and is most likely the issue in the background/content scripts if this is a wide spread issue.

tmashuang avatar Jan 21 '21 20:01 tmashuang

i have installed this extension: https://chrome.google.com/webstore/detail/run-javascript/lmilalhkkdhfieeienjbiicclobibjao i am working in windows 10 home and using google chrome: v 94.0.4606.81

after this I visit the stack overflow site since I want to make an extension for this site and I find this error in the chrome devtool:

It may be that you have the same or similar problem I will be reviewing this extension in search of what generates the error ...

image

wnunezc avatar Oct 22 '21 16:10 wnunezc

I can confirm that the error happen on any chromium browser when the browser is closed and opened from a dapp url

qwertynoone avatar Nov 16 '21 01:11 qwertynoone

It now happens on Superrare too, I guess most of the dApp are actually pretty sensible to this issue. Please can we swap the severity higher to get a quick fix?

qwertynoone avatar Nov 17 '21 14:11 qwertynoone

Facing similar issue on current latest chrome & Metamask (10.7.0), because of this error onboarding flow is not working as expected, it keeps logging 'Sending metamask:reload message' with error.

metamask-error

imaksp avatar Dec 06 '21 11:12 imaksp

what is dapp url?

wnunezc avatar Dec 06 '21 14:12 wnunezc

@jacobc-eth Hi, here is the minimal reproduction example based on this official guide: https://docs.metamask.io/guide/onboarding-library.html#using-react

Codesandbox URL: https://codesandbox.io/s/connect-metamask-forked-lph1y?file=/src/App.js

Direct app URL: https://lph1y.csb.app/

Also surprisingly it worked correctly one time (it closed the setup tab automatically & dapp received the event) while making this demo. & but I tried again many times by removing extension & installing again using this demo dapp, & if failed with mentioned error. & if possible please make this issue High priority.

imaksp avatar Dec 07 '21 05:12 imaksp

Excellent feedback by @aksdevac. Would appreciate prioritizing this issue. This issue is creating an inconsistent and confusing user experience.

ravisriv avatar Dec 07 '21 07:12 ravisriv

I can confirm that this is a problem with metamask and occurs in google chrome both on windows and macOSx, we have tried to install a completely new application and it follows the error only when the browser is first opened. This should be a high priority.

UPDATE:

It occurs on any website, the steps to reproduce them are as follows.

macOs: 11.5.2 Google Chrome: 96.0.4664.93 (Build oficial) (x86_64)

  1. Have metamask installed on Google Chrome
  2. Completely close Google Chrome
  3. Reopen Google Chrome and visit any page like: facebook.com
  4. You have the error in console: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
  5. *If you disable metamask, you don't have the error.

When you try to interact from the front-end with metamask with this error in the console, it is not possible.

thisprojectworks avatar Dec 09 '21 13:12 thisprojectworks

@thisprojectworks is correct, it seems it is now not limited to onboarding flow, Connecting does not work if you quit chrome & open dapp url first time, it starts working after you refresh the dapp page. hope this get fixed soon. also verified this on current dev chrome.

It only happens for 1st tab of new browser instance, if you open another tabs it works.

metamask-error-new-browser-instace

imaksp avatar Dec 20 '21 13:12 imaksp

Do you know if this already has a thread to follow in chrome ???

wnunezc avatar Dec 20 '21 14:12 wnunezc

Yes, I can confirm same issue here. I receive this issue from all pages where extension run.

Screenshot 2022-01-04 185331

passariello avatar Jan 05 '22 02:01 passariello

@thisprojectworks is correct, it seems it is now not limited to onboarding flow, Connecting does not work if you quit chrome & open dapp url first time, it starts working after you refresh the dapp page. hope this get fixed soon. also verified this on current dev chrome.

It only happens for 1st tab of new browser instance, if you open another tabs it works.

metamask-error-new-browser-instace

+1

dalechyn avatar Jan 24 '22 13:01 dalechyn

Does anybody have a momentary fix for this issue? I am wondering a force refresh upon the error message is a viable solution for now.

hamidmohammad1 avatar Jan 29 '22 15:01 hamidmohammad1

I'm having this issue too on macOs Chrome Reproduction:

  1. Quit Chrome
  2. Open Chrome
  3. Go to metamask docs example
  4. Click the 'enable ethereum' button, it does nothing
  5. Console shows the promise is forever pending, but the popup doesn't come up

Screenshot 2022-02-10 at 14 11 23

gVguy avatar Feb 10 '22 11:02 gVguy

Same issue here. It appears that it just happens if you open Chrome for the first time and your app then runs await window.ethereum.request({ method: 'eth_requestAccounts' }); If you refresh the page manually and try it again it works. This issue is open for a long time now, wondering if it this error comes with a new metamask/chrome version now again or if it is still the old error. It makes Metamask unusable... Anyone working on a fix??? Or workaround?

RobertoDonPedro avatar Feb 12 '22 05:02 RobertoDonPedro

Same issue here, I'm trying to check for existing connected wallets when the app loads.

   const isUnlocked = await window?.ethereum?._metamask.isUnlocked()
   if (isUnlocked) accounts = await window.ethereum.request({ method: 'eth_requestAccounts' })

it works fine if the browser is open, however restarting Chrome results in the error: Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.

It stops the execution of any other methods after it, resulting in an empty page. Any suggestions?

vphilot avatar Mar 14 '22 17:03 vphilot

I am getting the same error when trying to load the unpacked extension into Chrome after building from source. The Metamask popup either does not open or opens to a blank page and freezes.

Tried by building from source:

  • https://github.com/MetaMask/metamask-extension/commit/c81912f6c5561f70ef37acde0af8e0d723e531ec
  • Version 10.11.1

Chrome: Version 100.0.4896.30 (Official Build) beta (x86_64) macOS: 11.6.5

Screenshot 2022-03-14 at 20 39 14

loredanacirstea avatar Mar 14 '22 19:03 loredanacirstea

I am getting the same error when trying to load the unpacked extension into Chrome after building from source. The Metamask popup either does not open or opens to a blank page and freezes.

Tried by building from source:

Chrome: Version 100.0.4896.30 (Official Build) beta (x86_64) macOS: 11.6.5

Screenshot 2022-03-14 at 20 39 14

is it possible that the error is coming from another extension trying to do something to the popup.html window?

wnunezc avatar Mar 14 '22 19:03 wnunezc