I'm using ethers.js to connect to MetaMask. I keep seeing this warning in my console:

inpage.js:1 MetaMask: MetaMask will soon stop reloading pages on network change. For more information, see: https://docs.metamask.io/guide/ethereum-provider.html#ethereum-autorefreshonnetworkchange Set 'ethereum.autoRefreshOnNetworkChange' to 'false' to silence this warning.

I tried setting the value to false immediately after detecting window.ethereum - but I'm still getting this warning. Here's my code:

    try {
      if(window.ethereum) {
        window.ethereum.autoRefreshOnNetworkChange = false;
          .on('accountsChanged', accounts => {
          .on('chainChanged', () => {
        await window.ethereum.request({method: 'eth_requestAccounts'});
        //...do stuff
      else {
        throw new Error('Cannot connect to MetaMask or other Web3 wallet');
    catch(err) {
      throw err;

Am I putting the value in the wrong place? I tried moving that line around, and nope.

1 Answer 1


You might be accessing the said value even when it is undefined . Note by default it is "undefined" and not "true" or "false" . So put a check that whether it is even defined or not , before assigning any value to it .

if (typeof window.ethereum.autoRefreshOnNetworkChange !== "undefined") {
    window.ethereum.autoRefreshOnNetworkChange = false;

I used the above code in my method and it worked perfectly .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.