title: How to run chrome extension in background automatically?
body: <p>I want to create a chrome extension.
  I have a popup.html and also a background.js file.
  I want to create a countdown timer and also want it to run automatically.
  but the background.js file cannot access the popup.html.
  How to run scripts in backgrounds and automatically change the DOM?</p>
  
  <p>popup.html:</p>
  
  <pre><code>&lt;span class="time"&gt;20:00&lt;/span&gt;
  &lt;script src="background.js"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>background.js:</p>
  
  <pre><code>startTimer = (duration, display) =&gt; {
    let time = duration, minutes, seconds;
  
  
  setInterval(() =&gt; {
    minutes = parseInt(time / 60, 10);
    seconds = parseInt(time % 60, 10);
  
    minutes = minutes &lt; 10 ? "0" + minutes : minutes;
    seconds = seconds &lt; 10 ? "0" + seconds : seconds;
  
    display.innerHTML = `${minutes}:${seconds}`;
    if (--time &lt; 0) {
      time = duration;
    }
   }, 1000);
  }
  
  window.onload = () =&gt; {
    let duration = 60 * .1, display = document.querySelector('.time');  
    startTimer(duration, display);
  }
  </code></pre>