'Is there a workaround for Firefox 5 and Chrome ”setInterval()” and “setTimeout()” in inactive tab
There is a JavaScript optimization that causes inactive tabs to slow down setInterval()
and setTimeout()` in Firefox 5 and Chrome. I have it set for 66 miliseconds but it goes up to 1,000 when a tab is inactive.
There is way to determine how much time passed when the tab was inactive? I need JavaScript to keep running and performing actions, like playing sounds for some events.
Is there any way to achive that?
Solution 1:[1]
The whole point of those clamps is to keep background pages from using too much CPU. What events, exactly do you have going on in 15Hz that need to play sounds even though the user can't see the tab?
Solution 2:[2]
Mozilla is working on a different way of implementing setInterval and setTimeout, called requestAnimationFrame, perhaps it could help you solve your problem, or atleast hope for future updates that will take care of the problem.
Note that it is an experimental feature, beware of limitations when seeking cross-browser support.
https://developer.mozilla.org/en/DOM/window.mozRequestAnimationFrame
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Boris Zbarsky |
Solution 2 | simonauner |