'Google Chrome: how to fetch "minimized" event?
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?
Solution 1:[1]
I think this might help:
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.");
}
});
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
