Metamask-extension: Lost wakeup with ethereum.enable() using many browser tabs

Created on 17 Dec 2018  路  6Comments  路  Source: MetaMask/metamask-extension

When a dapp using ethereum.enable() is opened in two browser tabs, reloading two tabs at the same time locks one of them (the other loads successfully).

Steps to reproduce the behavior:

  1. Prepare the following HTML file:
<html>
<body>
<script type="text/javascript">
console.log('init');
ethereum.enable().then(() => console.log('enabled'));
</script>
</body>
</html>
  1. Open the HTML in two browser tabs
  2. Refresh the tabs quickly (for me it was not even necessary to use Refresh All)
  3. One tab logs 'init' and 'enabled', but the other one logs only 'init'

Both tabs should log 'init' and 'enabled' to the console.

Note that I had granted the permission for MetaMask to inject ethereum account for the location, so no popup appeared during the bug reproduction.
To reproduce, the HTML file location must be http://, file:// does not work.

Software versions:

  • Fedora release 29 (Linux 4.19.6)
  • Chromium 70.0.3538.110
  • MetaMask 5.2.2

All 6 comments

There are more cases of such behavior:
1) In development reloading of page in a background tab, triggered by recompiling source code also locks that page
2) When you reopen chrome browser it restores closed tabs. Metamask enabled page remains locked

+1!

the same issue is on my side guys

I have same issue!

Thanks for filing this @kkostalkowicz. We're investigating this issue now and hope to include a fix as part of the next release.

There is a workaround using an event listener.

Before you need any web3:

document.addEventListener('visibilitychange', this.enable, false)

Enable call:

enable = () => {
  if(document.hidden) return;

  window.ethereum.enable()
    .then((address) => { /* Your setup with enabled web3 */ })
    .finally(() => {
      document.removeEventListener('visibilitychange', this.enable, false)
    });
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

BMillman19 picture BMillman19  路  3Comments

estebanmino picture estebanmino  路  3Comments

johnerfx picture johnerfx  路  4Comments

hellobart picture hellobart  路  3Comments

1blockologist picture 1blockologist  路  3Comments