title: Error on chorme extension: Uncaught ReferenceError: window is not defined
body: <p>I'm developing a Chrome Extension (don't have a lot experience with it), and I've the following code:</p>
  <pre><code>window.onload = function () {
      validateCNPJ();
  };
  
  function validateCNPJ() {
      document.querySelector('div[data-field-name=&quot;CNPJ&quot;] &gt; input').addEventListener('keydown', (bla) =&gt; {
          let ble = bla.target.value;
          console.log(ble.length)
          if (ble.length &gt; 17) {
              bla.preventDefault()
              bla.stopPropagation()
              return
          }
  
          ble = ble.replace(/\D/g, &quot;&quot;)
          ble = ble.replace(/^(\d{2})(\d)/, &quot;$1.$2&quot;)
          ble = ble.replace(/^(\d{2}).(\d{3})(\d)/, &quot;$1.$2.$3&quot;)
          ble = ble.replace(/.(\d{3})(\d)/, &quot;.$1/$2&quot;)
          ble = ble.replace(/(\d{4})(\d)/, &quot;$1-$2&quot;)
          bla.target.value = ble;
      })
  }
  </code></pre>
  <p>I added window.load so that when the page loads, the validateCNPJ function is activated. That function validates a specific field in a form in real time.</p>
  <p>The issue is that when I upload the extension it shows a error message saying:</p>
  <pre><code>Uncaught ReferenceError: window is not defined
  </code></pre>
  <p>I tested the code inside the function validateCPNJ in the console of the browser and it worked normally.</p>
  <p>The manifest file is like this:</p>
  <pre><code>{
      &quot;name&quot;: &quot;CRM Validation Extension&quot;,
      &quot;description&quot;: &quot;Extension that validate fields of a opportunity&quot;,
      &quot;version&quot;: &quot;0.1&quot;,
      &quot;manifest_version&quot;: 3,
      &quot;background&quot;: {
          &quot;service_worker&quot;: &quot;background.js&quot;
      }
  }
  </code></pre>
  <p>What can I do to solve this issue?</p>
  <p>Thanks!</p>