It appears when you minimize a window or swap tabs, JavaScript's setInterval()
method starts becoming incredibly unreliable.
I just finished working on a time tracking feature on an app I'm working on, which is driven by setInterval
. This all worked perfectly until I started minimizing the window and coming back to it later, only to find out that the time had increased a small fraction of what it does when the window is up on the screen.
This seems to be a browser level "feature".
Is there an easy alternative I can swap this out for where units of time are actually honoured?
That seems to be a feature in some browsers such a Chrome in that tabs which are inactive/in the background are allowed a timeout period no smaller than 1000 milliseconds. You can read about it here
The common solution is to use Web Workers, as they will not be affected by this issue. In fact a few such solutions have been shown here before.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With