Korvo
Korvo

Reputation: 9724

Detecting user desktop inactivity using WebExtensions

I have an add-on and I want to issue notifications on the desktop, but only if the user is actively using the computer (e.g the mouse pointer is moving anywhere, i.e, not only in the browser window).

It is possible to do this using WebExtensions?

I believe it would be something like this:

Upvotes: 2

Views: 195

Answers (1)

Xan
Xan

Reputation: 77513

Chrome has a dedicated API, chrome.idle, to detect idle state.

chrome.idle.queryState(
  5 * 60, // seconds
  function(state) {
    if (state === "active") {
      // Computer not locked, user active in the last 5 minutes
    } else {
      // Computer is locked, or the user was inactive for 5 minutes
    }
  }
);

It also provides an event, chrome.idle.onStateChanged, to notify you when the state changes.


WebExtensions list this API as not yet supported (2016-07-21).

  • queryState always reports "active" state.
  • onStateChanged is not available.

Upvotes: 3

Related Questions