IdleDetector: change event
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only insecure contexts (HTTPS), in some or allsupporting browsers.
Experimental:This is anexperimental technology
Check theBrowser compatibility table carefully before using this in production.
Note: This feature is available inDedicated Web Workers.
Thechange event of theIdleDetector interface fires when the value ofuserState orscreenState has changed.
In this article
Syntax
Use the event name in methods likeaddEventListener(), or set an event handler property.
js
addEventListener("change", (event) => { })onchange = (event) => { }Event type
A genericEvent.
Example
In the following example, thechange callback prints the status ofuserState andscreenState to the console.
js
idleDetector.addEventListener("change", () => { const userState = idleDetector.userState; const screenState = idleDetector.screenState; console.log(`Idle change: ${userState}, ${screenState}.`);});Specifications
| Specification |
|---|
| Idle Detection API> # api-idledetector-onchange> |