idle.onStateChanged

Fired when the system changes to an active, idle or locked state. The event listener is passed a string that has one of three values:

  • "locked" if the screen is locked or the screensaver activates
  • "idle" if the system is unlocked and the user has not generated any input for a specified number of seconds. This number defaults to 60, but can be set using idle.setDetectionInterval().
  • "active" when the user generates input on an idle system.

Syntax

js
browser.idle.onStateChanged.addListener(listener)
browser.idle.onStateChanged.removeListener(listener)
browser.idle.onStateChanged.hasListener(listener)

Events have three functions:

addListener(listener)

Adds a listener to this event.

removeListener(listener)

Stop listening to this event. The listener argument is the listener to remove.

hasListener(listener)

Check whether listener is registered for this event. Returns true if it is listening, false otherwise.

addListener syntax

Parameters

listener

The function called when this event occurs. The function is passed this argument:

newState

idle.IdleState. The new idle state.

Examples

js
function newState(state) {
  console.log(`New state: ${state}`);
}

browser.idle.onStateChanged.addListener(newState);

Browser compatibility

desktop mobile
Chrome
Edge
Firefox
Opera
Safari
Firefox for Android
Safari on iOS
onStateChanged
Chrome – Full support
Chrome 6 (Release date: 2010-09-02)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – Full support
Firefox 51 (Release date: 2017-01-24)
footnote Full support
Opera – Full support
Opera 15 (Release date: 2013-07-02)
footnote Full support
Safari – No support
Safari
footnote No support
Firefox for Android – Full support
Firefox for Android 51 (Release date: 2017-01-24)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
locked
Chrome – Full support
Chrome 58 (Release date: 2017-04-19)
footnote Full support
Edge – Full support
Edge 79 (Release date: 2020-01-15)
footnote Full support
Firefox – No support
Firefox
footnote No support
Opera – Full support
Opera 45 (Release date: 2017-05-10)
footnote Full support
Safari – No support
Safari
footnote No support
Firefox for Android – No support
Firefox for Android
footnote No support
Safari on iOS – No support
Safari on iOS
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

Note: This API is based on Chromium's chrome.idle API. This documentation is derived from idle.json in the Chromium code.