title: Listener instantiated multiple times
body: <p>I'm developing a Chrome extension in which I have a popup that calls the "begin" function of background.js. Background.js opens tabs and I have a listener in background.js that sends a message to the content_script.js of the tabs:</p>
  
  <p>background.js</p>
  
  <pre><code>function begin() {
    var mySendedTabs = new Array();
    chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab)
    {             
     if(mySendedTabs.indexOf(tabId) == -1) {
      if(changeInfo.status == "complete")
      {
       chrome.tabs.sendMessage(tabId, { question: "What's your location ?" });
       mySendedTabs.push(tabId);                      
      }
     }                
   });
  }
  </code></pre>
  
  <p>content_script.js replies with another message:</p>
  
  <pre><code>chrome.runtime.onMessage.addListener(
   function(request, sender, sendResponse) {
    if(request.question == "What's your location ?") {
     alert("Got a location request");
     chrome.runtime.sendMessage({myLocation : location.href});
    }
  });
  </code></pre>
  
  <p>There is no problem when I refresh my extension from the "chrome://extensions/" window. The problem is that if I run my program a second time (from the popup), the alert in content_script.js is fired 2 times. If I run my program again, the alert is fired 3 times... and so on.</p>
  
  <p>It seen to me that the Listeners are still in memory although background.js is refreshed when I launch the program from popup, and that the Listeners are duplicated.</p>
  
  <p>If I call</p>
  
  <pre><code>chrome.tabs.onUpdated.removeListener(arguments.callee)
  </code></pre>
  
  <p>, all Listeners are removed and the program doesn't work anymore, even if I run the program again from popup.</p>
  
  <p>I just want to get a clean browser window when I launch the program from popup. </p>
  
  <p>I think I have to launch the listeners from the content scripts, that will not solve the problem but I don't know how to make singletons from my Listeners.</p>