chainChanged emits on page load
See original GitHub issueDescribe the bug
Sometimes chainChanged message emits on every page load. So if I have this line in my code: ethereum.on('chainChanged', (_chainId) => window.location.reload()); then user gets endless page refresh loop.
To Reproduce
I couldn’t reproduce this, but one of our user shared his screen and I saw this endless page refresh loop. I added console.log('chainChanged'); to that event callback, and console showed this log every time before page refreshed.
Expected behavior
chainChanged event should be sent only on chain change, not on page load
Browser details
- OS: OS X
- Browser: last Chrome
- MetaMask Version: 8.0.8
Issue Analytics
- State:
- Created 3 years ago
- Reactions:4
- Comments:13 (3 by maintainers)
Top Results From Across the Web
Ethereum Provider API - MetaMask Docs
This means that accountsChanged will be emitted whenever the user's exposed account address changes. Tip. We plan to allow the eth_accounts ...
Read more >How to emit chainId changed in flutter dapp browser
Good evening, in my dapp browser app, when the user requests a chain id change, i use to reload the page, but i...
Read more >How Can You Find the Ethereum Provider on Web3 Browsers ...
addEventListener('load', async function() { if (typeof ethereum !== 'undefined') { // Supports EIP-1102 injected Ethereum providers.
Read more >EIP-1193: Ethereum Provider JavaScript API
The Provider emits chainChanged when connecting to a new chain. ... Most Providers are available as window.ethereum on page load.
Read more >abcwallet-extension-provider-api - npm
ABC Wallet injects a global API into website visited by its users at `window.abc`.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@mehranhydary to fix this I store
lastChainIdinlocalStorageand onchainChainedcheck if it’s the same:I’m having this issue with Brave but not with Chrome.
Brave v1.34.81 Chromium: 97.0.4692.99 MetaMask v10.8.1