detect when a user is idle on a page
Last updated 3 years ago by loopmode .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install @xailabs/away 
SYNC missed versions from official npm registry.


Fork of away

detect idle users on webpages

var away = require('away');

// detect users who are idle for 10 seconds
var timer = away(10000);
timer.on('idle', function(tab) {
    console.log('user is idle');
    if (tab) console.log('>> user switched to another tab');
timer.on('active', function(tab) {
    console.log('user is active');
    if (tab) console.log('>> user switched back from another tab');


  • ES6 rewrite, transpiled via babel
  • Use passive events when possible
  • Detect tab change: User leaves tab -> idle, user comes back -> active


away() returns a Timer object which exposes the following methods.

.on('idle', fn)

Call fn when user becomes idle.

.on('active', fn)

Call fn when user becomes active after having been idle.


Stop the idle timer from detecting user activity


Start the idle timer. (By default the idle timer is started automatically)


idle() accepts a second argument with additional options.


The dom element to monitor for activity. (default document)


Milliseconds before user is considered idle. (default 30000)


String of DOM events that will trigger activity. (see index.js for default)


Value for the third argument in addEventListener. (if passive events are supported, the default is {passive: true}, otherwise it is false)


Whether to start idle timer upon creation. (default true)


Whether to detect tab changes (default true)
When the user switches between tabs, all idle and active callbacks are invoked immediatly and receive a boolean true as argument.

  • When the user switches to another tab, all idle callbacks are invoked
  • When the user switches back from another tab, all active callbacks are invoked

Use the boolean argument if you need to distinguish between regular user idleness/activity vs switching back and forth between tabs.


npm install away


Inspired by the jquery-idletimer plugin.

Current Tags

  • 2.0.0-rc7                                ...           latest (3 years ago)

10 Versions

  • 2.0.0-rc7                                ...           3 years ago
  • 2.0.0-rc6                                ...           3 years ago
  • 2.0.0-rc5                                ...           3 years ago
  • 2.0.0-rc4                                ...           3 years ago
  • 2.0.0-rc3                                ...           3 years ago
  • 2.0.0-rc2                                ...           3 years ago
  • 2.0.0-rc1                                ...           3 years ago
  • 1.0.4                                ...           3 years ago
  • 1.0.3                                ...           3 years ago
  • 1.0.2                                ...           3 years ago
Today 0
This Week 1
This Month 1
Last Day 1
Last Week 0
Last Month 0
Dependencies (1)
Dependents (0)

Copyright 2014 - 2016 © taobao.org |