title: chrome.windows.onFocusChanged.addListener fired when closing Chrome, crashing plugin
body: <p>I am writing a chrome extension, it uses <code>chrome.windows.onFocusChanged.addListener</code> to execute a content script. This works fine as long as I switch between different chrome windows however, the Listener is also fired when Chrome is closed. In that case the code inside the function leads to a crash of the extension.</p>
  
  <p>I tried chacking for undefined, but that does not seem to be the issue.</p>
  
  <p>The code lookls liks this</p>
  
  <pre><code>chrome.windows.onFocusChanged.addListener(function() 
  {
          var ctab = chrome.tabs.getCurrent;
          if(typeof  ctab === "undefined")
          {
  
          }
          else
          {
              chrome.tabs.executeScript(ctab.id,{file:"inject.js"}); //THIS LINE CRASHES THE APP WHEN I CLOSE THE BROWSER
          }
  });
  </code></pre>
  
  <p>I have a similar problem with a scheduled allert, which also executes the script (which leads to a crash when I close the browser between scheduling and execution).</p>
  
  <pre><code>function onAlarm(alarm) 
  {
      if (alarm &amp;&amp; alarm.name == 'check') 
      {
  
          var ctab = chrome.tabs.getCurrent;
          chrome.tabs.executeScript(ctab.id,{file:"inject.js"}); //CRASH
          //more code...
  </code></pre>
  
  <p>Does anybody know how to avoid this crash?</p>
  
  <p><strong>Edit: Working Example</strong></p>
  
  <p>manifest.json</p>
  
  <pre><code>{
   "name": "Rest Extension",
   "description": "Set an Artnet Controler to the background collor",
   "manifest_version": 2,
   "version": "1",
   "permissions": ["tabs", "http://*/*", "https://*/*", "background", "alarms"],
   "background": {"scripts": ["background.js"]},
   "content_scripts": [{"matches": ["http://*/*", "https://*/*"],"js": ["inject.js"]}],
   "browser_action": 
      {
          "default_icon": "16x16.png",
          "default_popup": "popup.html"
      }
  }
  </code></pre>
  
  <p>background.js</p>
  
  <pre><code>chrome.windows.onFocusChanged.addListener(function() 
  {
          var ctab = chrome.tabs.getCurrent;
          if(typeof  ctab === "undefined")
          {
  
          }
          else
          {
              chrome.tabs.executeScript(ctab.id,{file:"inject.js"}); //THIS LINE CRASHES THE APP WHEN I CLOSE THE BROWSER
          }
  })
  </code></pre>
  
  <p>all the other files can be empty (including the inject.js)</p>