How to close a chrome browser tab via terminal?

此生再无相见时 提交于 2020-07-19 07:52:58

问题


Currently I am writing a script that invokes a new instance of the chrome browser.

I know how to call chrome to open a *.html document in a new tab.

google-chrome *.html   

Chrome will open a new tab to show that file.

How can I close the tab in terminal without closing other tabs or closing the browser window?


回答1:


only linux answer:

Perhaps wmctrl could be of some assistance. You could use the -c option that closes a window gracefully:

wmctrl -c "tab title"

The string chrome is matched against the window titles. Note that the window might not close if some message pops-up (e.g. when you have multiple tabs open).




回答2:


You can look into chrome remote debugging:

chromium --remote-debugging-port=9222

and connect to it with some kind of client ( https://github.com/cyrus-and/chrome-remote-interface seems good). The debug protocol is used for a number of applications, but with some work you can achieve the kind of functionality you want. Here are some docs for you to check out: https://chromedevtools.github.io/devtools-protocol/tot/Page

Or perhaps chromix-too, which is based on an extension, daemon and client architecture.

https://github.com/smblott-github/chromix-too

This seems to be much easier to use, and might be exactly what you want, though the extension is a bit inconvenient, and there seems to be demand for more capabilities to be supported.



来源:https://stackoverflow.com/questions/20441793/how-to-close-a-chrome-browser-tab-via-terminal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!