title: Chrome Extension - Not able to add an element to Gmail Compose window
body: <p>I'm building a Google Chrome extension that will add a checkbox to the Compose/Reply window in Gmail. But the console is giving me an error message that it can't read the properties of appendChild (the function I'm using to add this checkbox to the window).</p>
  <p>Here's my manifest.json:</p>
  <pre><code>&quot;content_scripts&quot;: [
      {
          &quot;matches&quot;: [&quot;https://mail.google.com/mail/*&quot;],
          &quot;run_at&quot;: &quot;document_idle&quot;,
          &quot;js&quot;: [&quot;contentScript.js&quot;]
      }
  ],
  
  &quot;permissions&quot;: [  
      &quot;tabs&quot;,
      &quot;https://mail.google.com/*&quot;,
      &quot;storage&quot;      
    ]
  </code></pre>
  <p>And here is the relevant parts of my contentScript.js file, where the majority of my code is:</p>
  <pre><code>// Listen for Reply arrow (top reply) click
  let topReplyButton = document.getElementsByClassName('T-I J-J5-Ji T-I-Js-IF aaq T-I-ax7 L3');
  topReplyButton[0].addEventListener(&quot;click&quot;, addUpdateButton);
  
  function addUpdateButton() {
      let optionsArea = document.getElementsByClassName(&quot;aDh&quot;);
      if (optionsArea) {
          let mauticLabel = document.createElement('label');
          mauticLabel.setAttribute('name','mauticLabel');
          mauticLabel.innerHTML = &quot;Track with Mautic: &quot;;
          mauticLabel.setAttribute('id','mauticLabel');
          optionsArea[0].appendChild(mauticLabel);
  </code></pre>
  <p>And this is the error I get in the console when I click the reply button:</p>
  <pre><code>Uncaught TypeError: Cannot read properties of undefined (reading 'appendChild')
  at HTMLDivElement.addUpdateButton
  </code></pre>
  <p>So something seems to be wrong from the point when I create mauticLabel, but I haven't been able to figure out what's breaking.</p>
  <p>Thanks in advance :)</p>