title: Detect which tab/window is being focused in Google Chrome
body: <p>I'm making a Chrome extension that contains a content script that does the following:</p>
  
  <ul>
  <li>the content script is injected into every page</li>
  <li>periodically calls function "a" every 5 seconds</li>
  <li>if the page is in focus, it calls function "b".</li>
  </ul>
  
  <p>Ideally, function "a" should be called for every tab, but function "b" will only be called for the tab that is focused.</p>
  
  <p>I've looked into several ways of doing this, the closest solution I've found is this:
  <a href="https://stackoverflow.com/questions/2720658/how-to-detect-when-a-tab-is-focused-or-not-in-chrome-with-javascript">How to detect when a tab is focused or not in Chrome with Javascript?</a></p>
  
  <p>However, when I tried to use the outerHeight/innerHeight method, it gave me some really weird results. When the window is out of focus, I get 0 for outerHeight. Which seems more like a bug to me, so I'm not sure if I can use this to determine whether the tab is out of focus or not.</p>
  
  <p>Does anyone have a good solution for this?</p>