I'm trying to observe within my Firefox extension when a user is inactive. My current solution is derived from a similar question, found here (see accepted answer). And it basically works just fine.
I noticed, however, that it doesn't seem to distinguish between multiple open browser windows - that is, a user cannot be active in one window and inactive in another one. At the moment the active/inactive state is some global state across all Firefox windows. Thus, a user becomes really inactive, if the user is active in all open browser windows
Is there a way to distinguish between different windows, or do I have to deal with it (wouldn't be to bad, but still...)? Thanks a lot for any hints on that!
This is something that you will have to implement yourself. It also largely depends on what you mean by "inactive in a particular window". I guess that you mean the lack of mouse and keyboard activity in this window. So you would have to add a listener for keydown
, keyup
, mousemove
, mousedown
, mouseup
, DOMMouseScroll
, touchstart
, touchend
, touchmove
events. The listener for these events would set a timeout, e.g. for one minute. However, it would first clear the already existing timeout if any. This way the timeout will fire one minute after the last event received, one minute after the user stopped generated keyboard or mouse events in the window.