How can I make setInterval also work when a tab is inactive in Chrome?

后端 未结 13 1971
被撕碎了的回忆
被撕碎了的回忆 2020-11-21 09:59

I have a setInterval running a piece of code 30 times a second. This works great, however when I select another tab (so that the tab with my code becomes inacti

13条回答
  •  北荒
    北荒 (楼主)
    2020-11-21 10:44

    There is a solution to use Web Workers (as mentioned before), because they run in separate process and are not slowed down

    I've written a tiny script that can be used without changes to your code - it simply overrides functions setTimeout, clearTimeout, setInterval, clearInterval.

    Just include it before all your code.

    more info here

提交回复
热议问题