Linux 上的 Chrome - 查询浏览器以查看打开了哪些选项卡?

发布于 2024-10-16 17:15:28 字数 174 浏览 7 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

甜心 2024-10-23 17:15:28

Linux 上的 Chrome - 查询浏览器查看打开了哪些选项卡?

对于 chromium

strings ~/'.config/chromium/Default/Current Session' | 'grep' -E '^https?://'

Chrome on Linux - query the browser to see what tabs are open?

For chromium :

strings ~/'.config/chromium/Default/Current Session' | 'grep' -E '^https?://'
别靠近我心 2024-10-23 17:15:28

事实上,有一个命令行选项可以打开运行 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.

风和你 2024-10-23 17:15:28

这是一个更通用的解决方案(也适用于其他应用程序),通过使用 xdotool 查询焦点下的 X 窗口,

while true; do 
  xdotool getwindowfocus getwindowname; 
  sleep 10; 
done

例如,它输出以下内容:

Tilix: Defaultpeter-ThinkPad-T5801: peter@peter-ThinkPad-T580: ~
Chrome on Linux - query the browser to see what tabs are open? - Stack Overflow - Google Chrome
Local KVM
untitled — Atom
untitled — Atom
Open File
iostat_xtmz_3.out — ~/Work/KappAhl/Test1 — Atom
Tilix: Defaultpeter-ThinkPad-T5801: peter@peter-ThinkPad-T580: ~*

Here is a more general solution (works with other applications as well) by querying the X window under focus using xdotool

while true; do 
  xdotool getwindowfocus getwindowname; 
  sleep 10; 
done

This outputs the following for instance:

Tilix: Defaultpeter-ThinkPad-T5801: peter@peter-ThinkPad-T580: ~
Chrome on Linux - query the browser to see what tabs are open? - Stack Overflow - Google Chrome
Local KVM
untitled — Atom
untitled — Atom
Open File
iostat_xtmz_3.out — ~/Work/KappAhl/Test1 — Atom
Tilix: Defaultpeter-ThinkPad-T5801: peter@peter-ThinkPad-T580: ~*
时光瘦了 2024-10-23 17:15:28

上面的 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.

故事灯 2024-10-23 17:15:28

为此,我编写了一个工具来从 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文