I've ran into a known issue with chrome not being precise for setInterval()
calls. Consider the following code (jsfiddle: http://jsfiddle.net/periklis/j6AU8/), which displays a simple timer:
<span id = "time_left"></span>
<script>
seconds = 0;
minutes = 10;
hours = 0;
setInterval(function () {
if (seconds >= 1) {seconds--;}
else {
if (seconds == 0 ) {seconds = 59;}
if (minutes >= 1) {minutes--;}
else {
if (minutes == 0) {minutes = 59;}
if (hours >= 1) {hours--;}
else {hours = 0;}
}
}
min = minutes.toString();
sec = seconds.toString()
if (min.length == 1) {min = "0" + min;}
if (sec.length == 1) {sec = "0" + sec;}
document.getElementById("time_left").innerHTML = hours + ":" + min + ":" + sec;
}, 1000);
</script>
Using chromium (28.0.1500.52), I've opened the same script in 2 tabs, one having the focus and one hidden. After a while, if I switch to the hidden one, the timer has lagged behind for several seconds. The same holds true if the period is larger than 1'', say 2 or 3.
According to the link provided above, chrome should only exhibit similar behavior for calls less than 1''. Is there any (pure js, not jquery), work around this issue?