title: Uncaught TypeError: Cannot read property 'length' of undefined myTimer
body: <p>I have a web site which has a form where the user can enter their email, and upon submitting is sent to the next page. When I enter the email on this page, and I analyze the console, I see the following exception:</p>
  <blockquote>
  <p>Uncaught TypeError: Cannot read property 'length' of undefined myTimer @ VM567 content.js:43(anonymous function) @ VM567 content.js:40</p>
  </blockquote>
  <p>When I click on this, I see <code>content.js</code> as:</p>
  <pre><code>var gtmSnippet = document.createElement('script');
  gtmSnippet.title = 'TMI-INJECTED-GTM-CONTAINER-SNIPPET';
  gtmSnippet.id = 'tmigtmsnippet';
  
  var gtmTrigger = document.createElement('div');
  gtmTrigger.id = 'tmitriggerholder';
  
  var THEID;   
  
  function DB_setValue(name, value, callback) {
      var obj = {};
      obj[name] = value;
      console.log(&quot;Data Saved!&quot;);
      chrome.storage.local.set(obj, function() {
          if(callback) callback();
      });
  }
      
  chrome.runtime.sendMessage({greeting: &quot;SnippetPlease&quot;}, function(response) {
      THEID = response.farewell;
      if(response.farewell.length &gt; 0){
          gtmSnippet.text = &quot;//GTM CONTAINER INJECTION: \n(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],j=d.createElement(s),dl=l!='dataLayer'?'&amp;l='+l:'';j.async=true;j.src='//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);})(window,document,'script','dataLayer','&quot; + response.farewell + &quot;'); \n//GTM CONTAINER INJECTION ENDS\n&quot;;
          
          // Get a value saved in a form.
          var theValue = THEID;
          // Check that there's some code there.
          if (!theValue) {
              return;
          }
          else{
              DB_setValue('theid',theValue,function(){});
          }
      }
  });  
  
  40 var interval = setInterval(function(){myTimer()}, 0.1);
  
  41 function myTimer() {
  42    if((document.body != null) &amp;&amp; (THEID.length&gt;0)){
  43      // INJECT CONTAINER SNIPPET
  44      document.body.appendChild(gtmSnippet);
  45      
  46      stopInterval();
  47  }
  }
  
  function stopInterval() {
      clearInterval(interval);
  }
  </code></pre>
  <p>I have just started tinkering with JavaScript and I don't understand why this error is occurring, and</p>
  <p>How I could resolve it?</p>