Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including on-idle with all npm packages installed. Try it out:

var onIdle = require("on-idle")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

on-idle v3.1.4

Detect when the browser is idle

on-idle stability

npm version build status downloads js-standard-style

Safely detect when the browser is idle. Does nothing when run in Node.

on idle console screenshot

Usage

var onIdle = require('on-idle')
var html = require('bel')

var cancel = onIdle(function () {
  var el = html`<h1>browser is idle</h1>`
  document.body.appendChild(el)
})

if (somethingHappens) {
  cancel()
}

API

onIdle(callback, options)

Call a function when the browser has spare time. Calls it on the next frame if window.requestIdleCallback is not available. Does nothing in Node.

License

MIT

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free