detect when a user is idle on a page


Keywords
idle
License
MIT
Install
npm install @xailabs/away@2.0.0-rc3

Documentation

away

Wraps the away module and follows its API. Adds support for active/inactive tabs.

See https://www.npmjs.com/package/away

page visibility support

Sets up an additional visibilitychange listener to detects when the tab becomes active or inactive. When the tab visibility does change, the idle or active callback is invoked immediatly and receives true as indicator for tab activity.

Example:

import away from '@xailabs/away';
const activity = away(60000);
activity.on('idle', (tab) => {
    console.log('User became idle');
    if (tab) console.log('>> User switched to another tab');
});
activity.on('active', (tab) => {
    console.log('User became active');
    if (tab) console.log('>> User switched back from another tab');
});