title: MetaMask does not inject window.ethereum: Uncaught (in promise) TypeError: Cannot read property 'request' of undefined
body: <p>To start, let me mention this is an in-browser project, so i can only use</p>
  <pre><code>&lt;script src=&quot;https://cdn.jsdelivr.net/gh/ethereum/web3.js/dist/web3.min.js&quot;&gt;&lt;/script&gt;
  </code></pre>
  <p>So a few months back I made a dapp, which worked fine even tho I never set a provider, so I guessed it used the ones given by MetaMask.
  However, i am using the guide <a href="https://github.com/ChainSafe/web3.js" rel="noreferrer">here</a> the only issue is the following code,</p>
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var account_global, connected = false;
  
  async function connect() {
      if (!connected) {
          var wei;
          const accounts = await window.ethereum.request({ method: 'eth_requestAccounts' }); // Waits for connection to MetaMask.
          account_global = accounts[0];
          web3.eth.defaultAccount = account_global;
          console.log(account_global.toString() + " connected!");
          connected = true;
          console.log(account_global);
      }
  }
  
  connect();</code></pre>
  </div>
  </div>
  </p>
  <p>This code used to output the address of the metamask user after they approved metamask on my dapp, however I am receiving the error</p>
  <pre><code>Uncaught (in promise) TypeError: Cannot read property 'request' of undefined
  </code></pre>
  <p>The error just says that, my actual goal if i have to add providers and all is to use the ones from metamask, and allow connecting to metamask, the rest of the functions such as transfer or others i know how to handle them, it just seems that my issues come when i try loading the page.</p>
  <p>I dont have an ether node to use, not planning on using nodejs either, only a single html file displaying the Metamask address, hence using the in-browser web3js.</p>
  <p>I hope its just me not realizing something simple, because I cant seem to find the reason I cannot use web3js right now.</p>