问题
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