-2

I have a react app and I want to know how many times a user switch tabs in the browser and how many times the user minimize the browser separately. Is there a way to do it?

EDIT the current solution uses a combination of blur/focus and visibility API which covers all the cases of user navigating away. However, what I want is to count separately how many times user switched tabs vs how many times user minimized window. Blur/focus and visibility API events get fired in both tab switch and window minimize .

aryan
  • 133
  • 2
  • 8
  • 2
    No, but the dup Q gets you close. Does this answer your question? [Is there a way to detect if a browser window is not currently active?](https://stackoverflow.com/questions/1060008/is-there-a-way-to-detect-if-a-browser-window-is-not-currently-active) – Randy Casburn Dec 23 '20 at 16:21
  • @HymnZzy Using a combination of blur/focus and visibility API does cover all the cases but it does not allow differentitating them as both blur event and visibility API gets fired on minimizing the browser or switching tabs. What I want is to handle switching tabs and minimizing window separately. – aryan Dec 23 '20 at 16:24

1 Answers1

1

You cannot. Javascript stays within the page in the browser and doesn't interact with the browser features. Switching tabs and minimizing are browser features and not a webpage feature. Unless you have a browser that sends this event information to the webpage, which is very unlikely given the security issues, there is no solution for this as of today.

HymnZzy
  • 2,669
  • 1
  • 17
  • 27