title: window.setTimeout behaviour when window not in focus
body: <p>Here's the simplest code for reproducing I could think of:</p>
  
  <pre><code>ms = 30; // 1000 ?
  num = 1;
  function test()
  {
      num+=ms;
      document.getElementById('Submit').value = num; // Using native Javascript on purpose
      if (num &lt; 4000)
          window.setTimeout(test, ms);
  }
  test()
  </code></pre>
  
  <p>I set the ms (milliseconds between iterations) to <code>30</code>, ran the script and moved to different tab on the browser.</p>
  
  <p>Then I wait for about 10 seconds (the script should finish within 4 seconds) and came back to the tab.</p>
  
  <p>If I used Firefox I saw that the script has not finished, and the numbers are still running (resuming from where I left them, I guess).</p>
  
  <p>Which is annoying enough,</p>
  
  <p>But if I changed <code>ms</code> to 1000 and repeat the above steps, when I come back to the tab I saw the script has indeed already finished.</p>
  
  <p>(The script should still take 4 seconds to finish).</p>
  
  <p>Namely, sometimes Firefox runs window.setTimeout even if the window is out of focus, and sometimes it doesn't. Possibly depending on the duration</p>
  
  <p>On the other hand, this is not happening with Internet Explorer.</p>
  
  <p>It keeps running the script even if the tab is not focused. No matter how I set the <code>ms</code>.</p>
  
  <ul>
  <li><p>Is that due to some performance considerations of Firefox?</p></li>
  <li><p>What exactly is happening? </p></li>
  <li><p>How come such a basic thing is in consistent between browsers,
  nowadays?</p></li>
  </ul>
  
  <p>OR, am I working wrong? Is it a weird way for coding?</p>
  
  <p>I'm just trying repeatedly change the DOM, in a delayed fashion, without using setInterval (because I'm changing the interval it self on the go).</p>
  
  <ul>
  <li>And most important, how should I regard this?</li>
  </ul>
  
  <p>I can't assume my user won't leave the tab.</p>
  
  <p>I want to allow my user to leave the page for as mush as one might like.</p>
  
  <p>If one leaves and come back after half an hour, he/she will see irrelevant animations on the page, still running.</p>
  
  <p>Some of these animations are seen by all the users connecting to the page.</p>
  
  <p>There is no need they will be synchronized in resolution of milliseconds, but I can't start them only when the user put the tab/window in focus.</p>
  
  <p>I'm using Firefox 25.0.1, and IE 11. (Windows 7)</p>