You can try with Page Visibility API, it has the boolean property document.hidden (document.webkitHidden), which also detects whether current page is minimized or maximized. It is also dependant whether user has focused current browser tab or not:
https://developers.google.com/chrome/whitepapers/pagevisibility
https://developer.mozilla.org/en/DOM/Using_the_Page_Visibility_API