I need to execute some action only when the tab is the active/current tab in a given browser window.
I tried this:
let intID = setInterval(()=>{
if(document.visibilityState == "visible"){
//doSomething();
}
}, 1000);
and this:
let intID = setInterval(()=>{
if(!document.hidden){
//doSomething();
}
}, 1000);
Both the above examples don't work if the browser window is covered by another maximized window. As far as I could understand from other articles on the web, focus and blur don't do the job either. I specifically need something that will work even in a completely covered or even minimized window.