title: Chrome extension infinite loop
body: <p>I have an infinite loop that I do not understand</p>
  
  <pre><code>function bot(cartInfo, tab) {
      function injector(file, message) {
          chrome.tabs.executeScript(tab.id, {file: file, runAt: 'document_end'}, function(r) {
              chrome.tabs.sendMessage(tab.id, message, function(result) {
              });
          });
      }
  
      //this section gets repeated over and over
      chrome.tabs.onUpdated.addListener(
          function myListener(tabId, changeInfo, updateTab) {
              injector('addToCart.js', cartInfo.sizeInfo);
              chrome.tabs.onUpdated.removeListener(myListener);  
          } 
      );
  
  }
  </code></pre>
  
  <p>I want it to enter the addListner section call the injector( which runs another file addToCart) once and return and exit.  If I remove the line chrome.tabs.onUpdated.removeListener(myListener);  It will work but calls the injector function infinitely.  If I keep the line it exits the loop, but does not execute the injector.   Is there a way to get around this? or  a way to remove the listener while inside the addToCart file so I know it has been executed at least once?</p>