https://github.com/t-mullen/background-timer
Allows timeouts, intervals and animations to continue in background tabs.
https://github.com/t-mullen/background-timer
Last synced: 3 months ago
JSON representation
Allows timeouts, intervals and animations to continue in background tabs.
- Host: GitHub
- URL: https://github.com/t-mullen/background-timer
- Owner: t-mullen
- Created: 2017-10-05T20:04:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-08-17T21:00:07.000Z (almost 7 years ago)
- Last Synced: 2025-01-25T08:48:42.093Z (4 months ago)
- Language: JavaScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# background-timer
## [DEPRECATED: Use silent-audio instead.](https://github.com/RationalCoding/silent-audio)
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.
## Why?
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.## Install
NPM:
```shell
npm install --save background-timer
```
```javascript
const BackgroundTimer = require('background-timer')
```Script:
```html```
```javascript
window.BackgroundTimer
```## Examples
```javascript
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)
``````javascript
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)
```