从外部应用程序枚举浏览器选项卡
有点奇怪(具有挑战性?)的问题。 是否可以从外部应用程序以编程方式访问打开的浏览器的选项卡? 我意识到这是一个模糊的问题,但请听我说完:
我正在尝试创建一个“Gmail 聊天通知程序”应用程序,当存在未答复的聊天消息时,该应用程序会在 Windows 系统托盘中闪烁通知图标。 目前,据我所知,唯一内置的 Gmail 聊天通知是:
- 启用声音(我不喜欢)
- 观察窗口/选项卡/页面标题是否交替闪烁“Gmail”/“Blah 说。 ..“ 信息。
#2 的问题是:当浏览器窗口最小化,并且 Gmail 选项卡不是浏览器中的活动选项卡时,窗口标题不会更改,我也没有注意到新的内容聊天消息。
所以我想创建一个为我监视选项卡标题的应用程序。 (所有选项卡标题,而不仅仅是窗口标题,后者只是活动选项卡标题。)我创建了一个概念验证 C# 应用程序,通过枚举活动 Windows 进程并观察闪烁的“Blah”来检测未答复的聊天消息。窗口标题中说...”:
Process[] procs = Process.GetProcesses();
IntPtr hWnd;
foreach (Process proc in procs)
if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
if (proc.MainWindowTitle.IndexOf(" says… ") >= 0)
...
但明显的问题是,当 Gmail 选项卡不是活动/聚焦选项卡时,它不会工作(因为它只查看窗口标题)。 所以我需要一些可以更深入地挖掘并查看选项卡标题的东西。
我对任何事情都持开放态度。 我一直在想可能的工作是找到一种方法以某种方式枚举浏览器的选项卡(MDI子窗口?*手指交叉*),但也许这根本不可能:)我也开放如果有办法用 Firefox 插件或其他东西来做到这一点,也可以使用其他解决方案(但最好与 Windows 系统托盘集成,而不仅仅是存在于浏览器沙箱中)。
有人可以帮助我开始吗? 提前非常感谢。
A bit of an odd (challenging?) question. Is it possible to programmatically access the tabs of an open browser from a external application? I realize that's a vague question, but hear me out:
What I'm trying to create is a "Gmail Chat Notifier" application that flashes a notification icon in the Windows system tray when an unanswered chat message exists. Right now, as far as I can tell, the only built-in Gmail chat notifications are:
- Enable sounds (which I don't prefer)
- Watch the window/tab/page title for the alternating flashing "Gmail" / "Blah says..." message.
The problem with #2 is: When the browser window is minimized, and when the Gmail tab isn't the active tab in the browser, the window title doesn't change and I don't notice new chat messages.
So I'd like to create an application that watches the tab titles for me. (All of the tab titles, not just the window title, which is only the active tab title.) I created a proof-of-concept C# application to detect unanswered chat messages by enumerating the active Windows processes and watching for the flashing "Blah says..." in the window title:
Process[] procs = Process.GetProcesses();
IntPtr hWnd;
foreach (Process proc in procs)
if ((hWnd = proc.MainWindowHandle) != IntPtr.Zero)
if (proc.MainWindowTitle.IndexOf(" says… ") >= 0)
...
But the obvious problem with this is that it won't work when the Gmail tab isn't the active/focused tab (since it only looks at window titles). So I need something that can dig deeper and look at the tab titles.
I'm open to anything. What I had been thinking might work is finding a way to enumerate the browser's tabs somehow (MDI child windows? * fingers crossed *), but maybe that's not even close to possible :) I'm also open to other solutions too if there's a way to do this with, say, Firefox plugins or something (but it'd be nice to integrate with the Windows system tray, and not just exist in the browser sandbox).
Can anyone help get me started? Thanks much in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一般情况下是不可能的。 浏览器选项卡不必是 MDI 子窗口(事实上,它们几乎肯定不是)。 您不知道任意浏览器的窗口树,因此您无法解析它并找出选项卡(即使您知道特定浏览器的窗口树,它绝对是一个实现细节,即使在次要版本之间也可能会发生变化)。 事实上,您不知道浏览器是否为选项卡使用单独的 Win32 窗口句柄,因为它可能只有一个主窗口句柄,并自行绘制内部的所有内容(例如 Qt 和 WPF 应用程序就是这样做的,我相信Opera 尤其做到了这一点,Safari 可能也是如此)。
任何解决方案都必须针对特定浏览器。 您可能可以为 IE 和 Firefox 编写相应的插件,以将该信息传递给您的应用程序(尽管 Firefox 插件是沙盒的,所以我不确定它们是否能够执行 IPC)。 我没有看到任何适用于 Opera、Safari 或 Chrome 的选项。
It's not possible in general. Browser tabs need not be MDI child windows (in fact, they almost certainly aren't). You do not know the window tree of an arbitrary browser, so you can't parse that and figure out the tabs (and even if you knew it for a specific browser, it's definitely an implementation detail that is likely to change even between minor releases). In fact, you do not know if the browser is even using separate Win32 window handles for tabs, as it may just have one handle for its main window, and draw everything inside by itself (e.g. Qt and WPF applications do that, and I believe that Opera in particular does that, and probably so does Safari).
Any solution to this will have to be browser-specific. You can probably write corresponding plugins for IE and Firefox to communicate that info to your application (though Firefox plugins are sandboxed, so I'm not sure if they are even able to do IPC). I don't see any options for Opera, Safari or Chrome.