正在检测 Chrome 应用程序 Windows 打开

Detecting Chrome App Windows Opening

我正在尝试检测 Chrome 应用程序 windows 何时打开。

可以使用 chrome.windows.getAll({ populate: true, windowTypes: [ "app" ]}, callback) 获取当前打开的应用程序 windows,但是 chrome.windows.onCreated 事件不会为应用程序 windows 触发。

文档指出可以以某种方式为事件指定 window 类型的过滤器,但没有指定如何使用它。 chrome.windows.onCreated.addListener([ "app" ], callback) 失败 "Uncaught Error: Can't add listener"。

https://developer.chrome.com/extensions/windows#event-onCreated

过滤器在回调后被指定为一个对象。 App windows 打开可以使用 chrome.windows.onCreated.addListener(callback, { windowTypes: [ "app" ] })

观察

https://developer.chrome.com/extensions/events#filtered