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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4968271/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 02:48:58  来源:igfitidea点击:

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

linuxgoogle-chromechromiumdesktop-integration

提问by Rory

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?

我在 Ubuntu Linux 上运行 Chromium(开源 Chrome 版本)。我可以编写一个程序来查看我打开了哪些选项卡吗?我想编写一个程序来监控我花在事情上的时间。是否有命令行程序,某种调用chromium-browser 命令的方法,或者一些dbus 咒语,可以告诉我我打开了哪些选项卡以及每个选项卡所在的URL?

采纳答案by Maus

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.

事实上,有一个命令行选项可以为正在运行的 chrome (chromium) 进程打开大门--remote-shell-port。通过这个“调试后门”,您可以获取打开的选项卡列表。

UPDATE:

更新:

Chrome DevToolsis deprecated and not supported anymore since Version >17.0.950.* See WebKit-Protocolmanual if the new Debug-Framework provides similar manners to accomplish the task.

Chrome DevTools已弃用且不再受支持,因为版本 >17.0.950。*如果新的 Debug-Framework 提供类似的方式来完成任务,请参阅WebKit-Protocol手册。

回答by MevatlaveKraspek

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

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

For chromium:

对于chromium

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

回答by ptrk64

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

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

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: ~*