Reputation: 14957
This is perhaps the opposite of a very common problem: When you use setInterval
on one tab and you switch to another, the interval decreases significantly (i.e. slow down). This is very noticeable with audio timing since you can hear it being slowed down.
But on the latest Chrome 56 and Firefox 51, I can not make it happen anymore.
However on Chrome very rarely, and seemingly randomly, switching tabs can have an effect. And it even throttles Web Workers for some reason.
This is causing me headaches because I'm trying to write some Web Audio API stuff that requires very precise timing, and I cannot even see a difference between setInterval and Web Workers, which should be running on its own thread.
Why doesn't setInterval
act like it used to and throttle inactive tabs?
Update: Even a setInterval
within a Web Worker that has been loaded via a Blob URI, gets throttled in some cases, like switching tabs.
Upvotes: 4
Views: 1258
Reputation: 12478
Since javascript is a runtime compilation code( Compiled by browser at runtime, browser has to work on it). When you navigate to other tab, the page has it's own scripts and browser has to compile that code as well. So Browser assign a high priority to scripts in active tabs and scripts in remaining tabs are assigned with a lower priority. So it will affect scripts on inactive tabs. However if you have a machine with higher amount of RAM available, this problem will not occur.
Upvotes: 2