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.
This is an asynchronous function that returns a Promise
.
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.
This is an asynchronous function that returns a Promise
.
let querying = browser.idle.queryState(
detectionIntervalInSeconds // integer
)
detectionIntervalInSeconds
integer
. The system is considered idle if detectionIntervalInSeconds
seconds have elapsed since the last user input detected.
A Promise
that will be fulfilled with an idle.IdleState
string, indicating the current state.
Desktop | Mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | WebView Android | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | |
queryState |
Yes | 15 |
45Before version 51, Firefox always reports 'active'. After version 51, Firefox reports 'active' or 'idle' as appropriate. |
? | Yes | No | ? | ? |
48Before version 51, Firefox always reports 'active'. After version 51, Firefox reports 'active' or 'idle' as appropriate. |
? | No | ? |
locked |
Yes | 79 | No | ? | Yes | No | ? | ? | No | ? | No | ? |
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
function onGot(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!');
}
}
let querying = browser.idle.queryState(15);
querying.then(onGot);
Note: This API is based on Chromium's chrome.idle
API. This documentation is derived from idle.json
in the Chromium code.
© 2005–2023 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/idle/queryState