Idle Detection API
The Idle Detection API is a web API that allows a website or web application to detect when a user is idle, i.e. not actively interacting with their device.
Demo
Click on the button below and stop touching your device for 30 seconds.
How it works
The Idle Detection API goes beyond just detecting whether a tab is or visible and in focus , it considers both user activity (like mouse movements, keyboard input, or touch events) and device activity (like whether the screen is locked or the device is asleep). The API can return four different statuses:
userState: active→ the user is actively using their deviceuserState: idle→ the user is not actively using their devicescreenState: locked→ the screen is lockedscreenState: unlocked→ the screen is unlocked
Use cases
- Logging out users after inactivity for security reasons.
- Pausing sensitive operations or notifications when the user is away.
- Power-saving or optimizing resource usage in web apps when the user is idle.
- Tracking engagement in collaborative apps.
API
window.IdleDetector
Code
Links & Documentation
Ready to generate your PWA?
Try our PWA toolkit free of charge and without limits for 14 days. No credit card required.
Generate PWA See plans