11 ms·
I found some reasons for the inaccuracy of setTimeout: From https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#reasons_for_d
by lioeters 5y ago
I found some reasons for the inaccuracy of setTimeout:
From https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWorkerGlobalScope/setTimeout#reasons_for_delays https://developer.mozilla.org/en-US/docs/Web/API/WindowOrWor...
- Nested timeouts
> As specified in the HTML standard, browsers will enforce a minimum timeout of 4 milliseconds once a nested call to setTimeout has been scheduled 5 times.
- Timeouts in inactive tabs
> To reduce the load (and associated battery usage) from background tabs, browsers will enforce a minimum timeout delay in inactive tabs. It may also be waived if a page is playing sound using a Web Audio API AudioContext.
> The specifics of this are browser-dependent.
- Throttling of tracking scripts
> Firefox enforces additional throttling for scripts that it recognises as tracking scripts. When running in the foreground, the throttling minimum delay is still 4ms. In background tabs, however, the throttling minimum delay is 10,000 ms, or 10 seconds..
- Late timeouts
> The timeout can also fire later than expected if the page (or the OS/browser) is busy with other tasks.
- Deferral of timeouts during pageload
> Firefox will defer firing setTimeout() timers while the current tab is loading.