title: Preventing a Chrome extension's popup.html from opening itself
body: <p>I'm creating a Chrome extension that has a <code>background.html</code> file which requests information from an API once every minute. Once it receives the information, it messages <code>popup.html</code> with the JSON information with which popup uses to append new HTML elements onto the popup's body.</p>
  
  <p>The problem is background is constantly running (as it should), but it will ping popup even when popup is closed. This causes popup to open itself every minute which is very annoying.</p>
  
  <p>I want to know, is there a way to see if popup is closed and not do anything if that's the case? Or is there another way to prevent popup opening on its own?</p>
  
  <p>Here's the <a href="https://github.com/theabraham/Question-Stack" rel="noreferrer">Github repository</a>, but the important parts are highlighted below.</p>
  
  <p>Here's how I'm pinging popup:</p>
  
  <pre><code>// background.js
  
  function sendQuestions()                                                                                                                                                                                    
  {                                                                                                                                                                                                           
      var questions = JSON.parse(db.getItem(storage));                                                                                                                                                        
      chrome.extension.sendRequest(appid, { 'questions': questions }, function() {});                                                                                                                         
  }  
  
  setInterval(sendQuestions, 60e3);
  </code></pre>
  
  <p>Here's how popup handles it:</p>
  
  <pre><code>// popup.js
  
  chrome.extension.onRequest.addListener(function(request) {                                                                                                                                                  
      if (request.questions) {                                                                                                                                                                                
          displayQuestions(request.questions);                                                                                                                                                                
      }
  });
  
  function displayQuestions(questions)                                                                                                                                                                        
  {     
      for (i = 0; i &lt; questions.length; i++) {                                                                                                                                                                
          var question = questions[i];  
          var htmlBlock = // ... generate a block of html ...
          $('#container').prepend(htmlBlock);
      }
  }
  </code></pre>