Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
mohamedkhallouq
GitHub Repository: mohamedkhallouq/content
Path: blob/main/files/en-us/mozilla/add-ons/webextensions/api/idle/querystate/index.md
6552 views
---
title: idle.queryState() slug: Mozilla/Add-ons/WebExtensions/API/idle/queryState page-type: webextension-api-function tags: - API - Add-ons - Extensions - Idle - Method - Non-standard - Reference - WebExtensions - queryState browser-compat: webextensions.api.idle.queryState
---

{{AddonSidebar()}}

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.

Syntax

let querying = browser.idle.queryState( detectionIntervalInSeconds // integer )

Parameters

  • detectionIntervalInSeconds

    • : integer. The system is considered idle if detectionIntervalInSeconds seconds have elapsed since the last user input detected.

Return value

A Promise that will be fulfilled with an {{WebExtAPIRef('idle.IdleState')}} string, indicating the current state.

Browser compatibility

{{Compat}}

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

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);

{{WebExtExamples}}

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