SyntaxFix
Write A Post
Hire A Developer
Questions
Surprising to see nobody mentioned document.hasFocus
document.hasFocus
if (document.hasFocus()) console.log('Tab is active')
MDN has more information.