Based on Idle Detector API.
The Idle Detection API provides a means to detect the user's idle status, active, idle, and locked, specifically, and to be notified of changes to idle status without polling from a script.
Check the Browser compatibility table:
https://developer.mozilla.org/en-US/docs/Web/API/Idle_Detection_API#browser_compatibility