从外部应用程序枚举浏览器选项卡 [英] Enumerate browser tabs from external application

查看:24
本文介绍了从外部应用程序枚举浏览器选项卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有点奇怪(具有挑战性?)的问题.是否可以从外部应用程序以编程方式访问打开的浏览器的选项卡?我意识到这是一个模糊的问题,但请听我说完:

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:

我正在尝试创建一个Gmail 聊天通知程序"应用程序,当存在未答复的聊天消息时,它会在 Windows 系统托盘中闪烁通知图标.目前,据我所知,唯一的内置 Gmail 聊天通知是:

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:

  1. 启用声音(我不喜欢)
  2. 注意窗口/标签/页面标题交替闪烁的Gmail"/Blah say..."消息.

#2 的问题是:当浏览器窗口最小化,并且 Gmail 选项卡不是浏览器中的 活动 选项卡时,窗口标题不会改变,而我不会不会注意到新的聊天消息.

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.

所以我想为我创建一个监视标签标题的应用程序.(所有选项卡标题,不仅仅是窗口标题,它只是活动选项卡标题.)我创建了一个概念验证 C# 应用程序,通过枚举活动 Windows 进程并观察闪烁的Blah"来检测未答复的聊天消息说..."在窗口标题中:

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)
        ...

但明显的问题是,当 Gmail 选项卡不是活动/焦点选项卡时它不起作用(因为它只查看窗口标题).所以我需要一些可以深入挖掘并查看标签标题的东西.

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.

我对任何事情都持开放态度.我一直认为可能的工作是找到一种方法来以某种方式枚举浏览器的选项卡(MDI 子窗口?* 手指交叉*),但也许这甚至不可能:) 我也打开如果有办法使用 Firefox 插件或其他东西(但最好与 Windows 系统托盘集成,而不仅仅是存在于浏览器沙箱中),也可以使用其他解决方案.

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.

推荐答案

一般情况下是不可能的.浏览器选项卡不必是 MDI 子窗口(事实上,它们几乎肯定不是).您不知道任意浏览器的窗口树,因此您无法解析它并找出选项卡(即使您知道特定浏览器的它,它也绝对是一个实现细节,即使在次要版本之间也可能会发生变化).实际上,您不知道浏览器是否甚至为选项卡使用单独的 Win32 窗口句柄,因为它可能只有一个主窗口句柄,并在其内部绘制所有内容(例如 Qt 和 WPF 应用程序这样做,我相信Opera 尤其如此,Safari 也可能如此).

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).

对此的任何解决方案都必须是特定于浏览器的.您可能可以为 IE 和 Firefox 编写相应的插件来将该信息传达给您的应用程序(尽管 Firefox 插件是沙盒的,所以我不确定它们是否能够进行 IPC).我没有看到 Opera、Safari 或 Chrome 的任何选项.

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.

这篇关于从外部应用程序枚举浏览器选项卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆