Skip to content

An override to JavaScript's default setInterval() function that behaves better when in a background tab/window.

Notifications You must be signed in to change notification settings

bendemeyer/setinterval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

setinterval

An override to JavaScript's default setInterval() function that behaves better when in a background tab/window.

I've noticed that in some browsers, when a window running a repetetive event implemented with setInterval() is switched to the background and then brought back to the foreground, the browser will freeze as it rushes to run all of the setInterval() events that should have been run while the window was in the background. For whatever reason, this issue does not seem to occur when setTimeout() is used instead and called recursively.

To fix this, I've writting this override function which replaces setInterval and clearInterval with custom functions that use recursive calls to setTimeout to create repetetive actions. The syntax and behavior are exactly the same as the standard setInterval function, so it can be dropped into any system to fix the flaws of setInterval without breaking existing code.

About

An override to JavaScript's default setInterval() function that behaves better when in a background tab/window.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published