Idle Detection API is a browser API that tells a web page when the user has stopped interacting with their device or when the screen is locked. It is exposed as the IdleDetector class in secure contexts and is a Web Platform Incubator Community Group draft. The spec's motivating case is sending notifications to the device a person is actually using, and the shortest threshold you can ask for is 60,000 milliseconds.
IdleDetector reports two separate states. userState is "active" or "idle", and it describes input such as keyboard, mouse or touch in the last threshold milliseconds. screenState is "locked" or "unlocked", and it reports whether a screensaver or lock screen hides the content. Both are null until detection has started.
The flow has three steps:
If the threshold is less than 60,000, start() returns a promise rejected with a TypeError. The spec explains that the floor of 60 seconds exists to limit how finely a site can infer typing behavior, and the permission prompt guards against profiling when and how long a user is active. The class is exposed in windows and dedicated workers, but requestPermission() is window-only.
The permission policy has the same name, and its default allowlist is 'self'. A site can switch it off entirely with the response header Permissions-Policy: idle-detection 'none'. The sample reproduces the threshold rule, since Node has no IdleDetector.
const MIN = 60000;
function start(threshold) {
if (threshold < MIN) return "TypeError: threshold " + threshold + " is below " + MIN;
return "ok: idle after " + threshold / 1000 + " s without input";
}
console.log(start(500));
console.log(start(59999));
console.log(start(60000));
console.log(start(5 * 60 * 1000));
Output:
TypeError: threshold 500 is below 60000
TypeError: threshold 59999 is below 60000
ok: idle after 60 s without input
ok: idle after 300 s without input
The minimum threshold is 60,000 milliseconds, which is 60 seconds. Any smaller value makes start() reject with a TypeError, so there is no way to detect a two-second pause. Pick a value that matches your product, such as 300,000 for five minutes.
MDN compatibility data lists IdleDetector in Chrome 94 and Opera 80, and in Edge 114, with no support in Firefox or Safari. The API is flagged as experimental. Feature-detect with "IdleDetector" in window and fall back to timers on input events.