Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect user inactivity in chrome?

I want to fire a method when users is not using chrome (say after 5mins) and fire another when user becomes active. How to do this?

like image 728
dasfdsa Avatar asked Dec 01 '16 06:12

dasfdsa


People also ask

How do I turn off idle detection in chrome?

Navigate to Idle Detection and Turn It Off Just copy and paste “chrome://settings/content/idleDetection” into your address bar. You can then decide the default behavior to completely disable Idle Detection.

What is idle detection?

“The Idle Detection API notifies developers when a user is idle, indicating such things as lack of interaction with the keyboard, mouse, screen, activation of a screensaver, locking of the screen, or moving to a different screen. A developer-defined threshold triggers the notification,” Google said in a blog post.


1 Answers

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. If you want to know whether the user is inactive in a browser window, you can see the post - Is there a way to detect if a browser window is not currently active?

like image 192
Wasi Ahmad Avatar answered Oct 16 '22 08:10

Wasi Ahmad