Linux 上的 Chrome - 查询浏览器以查看打开了哪些选项卡?
我在 Ubuntu Linux 上运行 Chromium(开源 chrome 版本)。我可以编写一个程序来查看我打开了哪些选项卡吗?我想编写一个程序来监控我在事情上花费了多少时间。是否有命令行程序,某种调用 chromium-browser 命令的方法,或者一些 dbus 咒语可以告诉我打开了哪些选项卡以及每个选项卡所在的 URL?
I am running Chromium (the open source chrome version) on Ubuntu Linux. Can I write a programme to see what tabs I have open? I would like to write a programme to monitor how much time I'm spending on things. Is there a command line programme, some way to invoke the chromium-browser command, or some dbus incantation that will tell me what tabs I have open and what URL each tab is at?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Linux 上的 Chrome - 查询浏览器查看打开了哪些选项卡?
对于
chromium
:Chrome on Linux - query the browser to see what tabs are open?
For
chromium
:事实上,有一个命令行选项可以打开运行 chrome (chromium) 进程
--remote-shell-port
的大门。通过这个“调试后门”,您可以获取打开的选项卡列表。更新:
Chrome DevTools 已弃用,自版本 > 17.0 起不再受支持.950.*
如果新的调试框架提供了类似的方式来完成任务。
Indeed there is a command line option which can open the door to a running chrome (chromium) process
--remote-shell-port
. Through this "debugging back-door" you may be able the get the list of open tabs.UPDATE:
Chrome DevTools is deprecated and not supported anymore since Version >17.0.950.*
See WebKit-Protocol manual if the new Debug-Framework provides similar manners to accomplish the task.
这是一个更通用的解决方案(也适用于其他应用程序),通过使用 xdotool 查询焦点下的 X 窗口,
例如,它输出以下内容:
Here is a more general solution (works with other applications as well) by querying the X window under focus using xdotool
This outputs the following for instance:
上面的 unix 命令的扩展(我没有足够的声誉来评论)。我试图只获取标签数。这仍然不完美,因为我认为该文件包含其中所有选项卡的完整历史记录。我猜它们是按顺序排列的,但如何区分它们并不明显。
字符串 ~/Library/Application\ Support/Google/Chrome/Default/Sessions/Tabs_* | sed -nE 's/^([^:]+):\/\/(.*)\/$/\2/p' | grep -v“新标签” | grep -v“新标签页”|排序|优衣库 | wc -l
这是在 Mac 上,因此您的路径和 sed 选项可能会有所不同。
基本思想是去掉尾部斜杠(很多重定向只是添加斜杠)和新标签,这样我们就可以获得准确的计数。对于我当前的选项卡文件,打开的选项卡数从 181 个减少到 35 个。实际上现在看起来计数不足,但已经接近很多了。
An expansion on the unix command above (I don't have enough reputation to comment). I was trying to just get a count of tabs. This still isn't perfect because I think the file has the entire history of all tabs in it. I guess they are in order, but not obvious how to separate them.
strings ~/Library/Application\ Support/Google/Chrome/Default/Sessions/Tabs_* | sed -nE 's/^([^:]+):\/\/(.*)\/$/\2/p' | grep -v "newtab" | grep -v "new-tab-page" | sort | uniq | wc -l
This is on mac, so your paths and sed options may vary.
The basic idea is to get rid of trailing slashes (lots of redirects just add a slash) and newtabs so we can get an accurate count. For my current tabs file this went from 181 tabs open down to a count of 35. That actually looks like an undercount right now, but it is a lot closer.
为此,我编写了一个工具来从 Chrome 会话文件中提取数据。 https://github.com/lemnos/chrome-session-dump。像 chrome-session-dump 这样运行它会生成一个选项卡列表(按顺序),随后可以将其传递给 Firefox。 EG chrome-session-dump|xargs 火狐。您还可以通过 -active 获取当前打开的选项卡,以供外部脚本处理。
I have written a tool to extract data from chrome session files for precisely this purpose. https://github.com/lemnos/chrome-session-dump. Running it like so chrome-session-dump will produce a list of tabs (in order) which can subsequently be passed to firefox. E.G chrome-session-dump|xargs firefox. You can also obtain the currently open tab via -active for processing by external scripts.