0

I try to fetch all events when the state of a window changes. So far, I use a content script that adds a "resize" listener to the window: window.onresize = function() {...}. This allows me to fetch when a window's state changes to "normal", "maximized" and "fullscreen".

However, I have no idea what to do to also get "minimized". Minimizing a window does not fire "resize" events. I tried to use the onFocusChanged API to add an listener, i.e., chrome.windows.onFocusChanged.addListener(function(windowId) {...}));, but it has its issues. Firstly, if the window I minimize has the focus, windowId = -1 (chrome.windows.WINDOW_ID_NONE), so I cannot fetch the window to readout its state. And secondly, if the window doesn't have the focus, the onFocusChanged event is not fired.

In short, how can I detect when a Chrome window has been minimized. Thanks a lot for any hints

4

1 回答 1

0

我认为这可能会有所帮助:

chrome.windows.onFocusChanged.addListener(function() {
    console.log("Focus changed.");

    chrome.windows.getCurrent(function(window){
        console.log(window.state);
        if(window.state == "normal") {
            console.log("It's normal.Stop the watch.");
        } else if(window.state == "maximized"){
            console.log("It's maximized.Start the watch.");
        } else if(window.state == "minimized"){
        console.log("It's minimized.Start the watch.");
        }
    });
});
于 2014-05-13T08:10:42.547 回答