简体   繁体   English

Chrome扩展程序窗口侦听器-最小化

[英]Chrome extension window listener - on minimized

I'm creating a small chrome extension, and I am having trouble figuring out what I should do to check whether a window is minimized or not. 我正在创建一个小的chrome扩展程序,并且在确定应该如何检查窗口是否最小化时遇到麻烦。

So far I am using chrome.tabs.onActivated and chrome.tabs.query together to listen for a tab change and it works as expected, but now my problem is I also need it to know when the browser window is minimized. 到目前为止,我在一起使用chrome.tabs.onActivatedchrome.tabs.query来监听选项卡的更改,它可以按预期工作,但是现在我的问题是我还需要它知道何时最小化浏览器窗口。

chrome.tabs.onActivated.addListener(function() {
    chrome.tabs.query({currentWindow: true, active: true}, function(tabs){
        //do something
    });
});

I have also looked at onFocusChanged but that only seems to work with multiple browser windows. 我也看过onFocusChanged,但这似乎只能在多个浏览器窗口中使用。

How to check that the browser window is minimized? 如何检查浏览器窗口是否最小化?

It's easy if you have the window ID, you can then get the Window object : 如果您具有窗口ID,则很容易,然后可以获取Window对象

chrome.windows.get(windowId, function(win){
  if(window.state == "minimized") {
    /* ... */
  }
});

If you need the current window, use getCurrent instead: 如果需要当前窗口,请改用getCurrent

chrome.windows.getCurrent(function(win){
  if(window.state == "minimized") {
    /* ... */
  }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM