There is few options to check it:
-
Using Visibility API
-
Using
focus
andblur
events to detect browser tab visibility:
window.addEventListener("focus", handleBrowserState.bind(context, true)); window.addEventListener("blur", handleBrowserState.bind(context, false)); function handleBrowserState(isActive){ // do something }
- Using timers, as mentioned above