Possible duplicate:
Chrome: timeouts / interval paused on background tabs?
Is there a minimum allowable delay for setInterval()
and setTimeout()
when starting on a tab that you are not looking at right now?
This code runs setInterval()
with a specified delay of 100 ms and records how long the delay has been. It also reports when you enter / leave the tab.
<html> <body> <script type="text/javascript"> window.onfocus = function () { document.body.innerHTML += 'entered tab<br />'; }; window.onblur = function () { document.body.innerHTML += 'left tab<br />'; }; var previous = new Date().getTime(); setInterval(function () { var now = new Date().getTime(); var elapsed = now - previous; document.body.innerHTML += elapsed + '<br />'; previous = now; }, 100); </script> </body> </html>
Here's an excerpt from the output on Chrome 12.0.742.100 on Ubuntu 10.04.2 LTS:
101 101 101 left tab 1001 1000 1004 1003 1002 1000 entered tab 101 101 101 102 101
I also tried different values ββfor the delay. Any value less than 1000 leads to the same behavior that it increases to 1000 when you look at another tab. Values ββgreater than 1000 behave correctly. The same thing happens with the setTimeout()
version of this code.
source share