How to make JavaScript run at normal speed in Chrome even when tab is not active?

▼魔方 西西 提交于 2019-12-07 06:46:03

问题


I've noticed a problem with my webapp - when Chrome active tab isn't set to my app, Chrome stops running my JS code until I open tab again.

I guess it does to save CPU cycles. Else if you've 20 tabs open and each has code running, it will get slow quickly.

This is all good, but my app requires that it keeps running in the background. It updates graphs in real time and analyses data every few seconds.

If I move to another tab, graph updating and analysis stops (or becomes very slow - 1 second is now like 20 seconds). Then when I focus on tab again it resumes updating at normal speed but the graphs and data analysis gets weird because of this weird time dilution.


回答1:


Playing a faint sound seems to unlock full javascript performance in the background, yet, using websockets does not

Here's a more lengthy answer I've written: https://stackoverflow.com/a/51191818/914546



来源:https://stackoverflow.com/questions/32390789/how-to-make-javascript-run-at-normal-speed-in-chrome-even-when-tab-is-not-active

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!