package
Allows timeouts, intervals and animations to continue in background tabs.
npm install background-timerGitHub-flavored package documentation.
Across all versions.
Download trend unavailable.
Runtime metadata.
Allows timeouts, intervals and animations to continue in background tabs.
Timers will use regular methods when the tab is focused, and rely on timers within a small popup window when out of focus.
Chrome and Firefox throttle timers in background tabs to prevent abuse of resources. Unfortunately, well-behaving apps are sometimes broken by this policy. This provides a workaround, while still allowing the user to "opt-out" by closing the popup window.
NPM:
npm install --save background-timerconst BackgroundTimer = require('background-timer')Script:
<script src="dist/background-timer.js">window.BackgroundTimer element.addEventListener('click', function () { // must be triggered by user event
BackgroundTimer({global: true}) // override globals with this option
})
window.requestAnimationFrame(function () {}, 50)
window.setInterval(function () {}, 50)
window.setTimeout(function () {}, 50)
window.cancelAnimationFrame(id)
window.clearInterval(id)
window.clearTimeout(id) element.addEventListener('click', function () { // must be triggered by user event
var backgroundTimer = new BackgroundTimer({global: false}) // it's cleaner to avoid globals
})
backgroundTimer.requestAnimationFrame(function () {}, 50)
backgroundTimer.setInterval(function () {}, 50)
backgroundTimer.setTimeout(function () {}, 50)
backgroundTimer.cancelAnimationFrame(id)
backgroundTimer.clearInterval(id)
backgroundTimer.clearTimeout(id)