Please note, this is a STATIC archive of website developer.mozilla.org from November 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

idle.queryState()

Returns "locked" if the system is locked, "idle" if the user has not generated any input for a specified number of seconds, or "active" otherwise.

Syntax

chrome.idle.queryState(
  detectionIntervalInSeconds, // integer
  function(newState) {...}    // function
)

This API is also available as browser.idle.queryState() in a version that returns a promise.

Parameters

detectionIntervalInSeconds
integer. The system is considered idle if detectionIntervalInSeconds seconds have elapsed since the last user input detected.
callback
function. The function is passed the following arguments:
newState
idle.IdleState. The idle state.

Browser compatibility

Chrome Edge Firefox Firefox for Android Opera
Basic support Yes No 45.0 48.0 33

Compatibility notes

Firefox

  • Before version 51, Firefox always reports 'active'. After version 51, Firefox reports 'active' or 'idle' as appropriate. 'locked' is not supported.

Firefox for Android

  • Before version 51, Firefox always reports 'active'. After version 51, Firefox reports 'active' or 'idle' as appropriate. 'locked' is not supported.

Examples

In this simple snippet, we call queryState() and then check if the returned newState is idle or active, logging a message as appropriate. Because we have specified  a detectionIntervalInSeconds of 15, an idle state will only be reported if there has been no user activity for at least 15 seconds

chrome.idle.queryState(15,function(newState) {
  if(newState === 'idle') {
    console.log('Please come back — we miss you!');
  } else if(newState === 'active') {
    console.log('Glad to still have you with us!');
  };
});

Acknowledgements

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

Microsoft Edge compatibility data is supplied by Microsoft Corporation and is included here under the Creative Commons Attribution 3.0 United States License.

Document Tags and Contributors

 Contributors to this page: wbamberg, Makyen, chrisdavidmills, kmaglione
 Last updated by: wbamberg,