I am building a trivia quiz game (as a side feature of a main app), and as with any online trivia, obviously you can cheat by googling the answer. However, I want to detect basic navigation away from the current/tab window, as this is a simple way of seeing if a user navigated away from the focused site while answering (I will penalize their score if they do).
I have used the Page Visibility API, detailed in this answer https://stackoverflow.com/a/1060034/5579458 - however it only works if the user changes tabs, or minimizes/maximizes the window. The onchange event is not triggered if the user leaves the tab active, but maximizes another program over it from the taskbar or places focus on another window. How can we program this?