Is there any DOM event for when the browser tab loses/gains focus? I know there are the blur and focus events on window, but they also
The closest thing I believe you'll find is the top answer here:
Is there a way track the focus on tab with Javascript?
At least Google Chrome supports a webkitvisibilitychange event and a document.webkitHidden property. See the visibility API. But it seems only to fire when the shown tab changes, not when the whole window is minimized. There also seems to be a visibilitychange event for Internet Explorer, but the documentation doesn't say anything about it.
Now they have exactly what was needed: https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API