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?
            Asked
            
        
        
            Active
            
        
            Viewed 3,367 times
        
    1 Answers
10
            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?
 
    
    
        Community
        
- 1
- 1
 
    
    
        Wasi Ahmad
        
- 35,739
- 32
- 114
- 161
- 
                    Thanks. I was looking for it in chrome.tabs. – dasfdsa Dec 01 '16 at 06:52
- 
                    2What is considered as _idle_ here? Say, if I minimize all Chrome windows and move my mouse cursor around, is it “_idle_” for Chrome? – Константин Ван Aug 25 '19 at 07:50
