How to make JavaScript run at normal speed in Chro

2019-05-01 04:30发布

问题:

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