'Chrome packaged app having an onblur listener

Is there any event listeners for a Chrome packaged app to tell if the app has lost focus? I'm trying to make a game, but I can't seem to make it pause when I change the focus.

I've tried a few different things such as the following, but none seem to work.

document.onblur = pause;
document.addEventListener('blur', pause, false);

canvas.onblur = pause;
canvas.addEventListener('blur', pause, false);

window.onblur = pause;
window.addEventListener('blur', pause, false);

chrome.app.window.onblur = pause;
chrome.app.window.onBlur = pause;
chrome.app.window.onblurred = pause;
chrome.app.window.onBlurred = pause;
chrome.app.window.addEventListener('blur', pause, false);

chrome.app.window.current().onblur = pause;
chrome.app.window.current().onBlur = pause;
chrome.app.window.current().onblurred = pause;
chrome.app.window.current().onBlurred = pause;
chrome.app.window.current().addEventListener('blur', pause, false);

Any ideas? I can literally copy this entire list into my code and not a single one fires a pause.

I'm lost and Google has 3 results with some non-related things, then more with omitted works that I find important.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source