I have JavaScript that is doing activity periodically. When the user is not looking at the site (i.e., the window or tab does not have focus), it\'d be nice to not run.
this worked for me
document.addEventListener("visibilitychange", function() { document.title = document.hidden ? "I'm away" : "I'm here"; });
demo: https://iamsahilralkar.github.io/document-hidden-demo/