Is there a way to reload a Google Chrome tab in Ubuntu using just the terminal. I don't want to just open a new window, but to actually refresh a tab!
Extra question: Is this possible in other browsers as well such as Opera, Safari, Firefox.
Is there a way to reload a Google Chrome tab in Ubuntu using just the terminal. I don't want to just open a new window, but to actually refresh a tab!
Extra question: Is this possible in other browsers as well such as Opera, Safari, Firefox.
Important note: a probably better answer has been posted after this one, please also see that answer, based on the Chromix-Too tool, and use the one you prefer for your use case.
This answer starts from the solution kindly provided by blackloop, but it can work with multiple windows and let you select the right tab in the right window, by using string comparison for tab titles and by using the capability of some browsers to select a specific tab by sending keystrokes.
The code has two parameters: the tab position in the window (a number from 1 to 8) and a substring of the tab title, to identify the correct tab.
The code below is based on Google Chrome, see comment on some code lines to learn how to change it for the Firefox case (or you can modify it to take the browser name in input).
Save this code in a file, say for example
tab_refresh.sh
(Note: this code extends this code as in the answer by blockloop)
After creating the file, make it executable, for example by typing:
Finally, to use this script, you have to type something like:
For example, say you want to update the 4th tab in a Google Chrome window where its 4th tab title contains the string
foo
.Probably this could be a (the easiest) solution for your problem
https://unix.stackexchange.com/questions/87831/how-to-send-keystrokes-f5-from-terminal-to-a-process
Edit: This should work for other browsers too without problems
Looks like user2974830's answer is using some incorrect (perhaps old) syntax for xdotool.
--search
is supposed to be justsearch
(without the dashes) and--windowid
is supposed to be--window
That being said here's a more comprehensive solution that I found here. The link uses inotifywait, but I prefer entr which wraps inotifywait.
I saved it to a file called
reload-chrome-nix
and I runfind . -type f | entr ./reload-chrome-nix
That's all you need.
Solution: chromix-too
Chromix-Too is a tool to send many types of commands to an existing Chrome session via command line, include tab reloading, given a tab identifier. As described here it is composed of three components: an extension for Google Chrome, a server and the
chromix-too
utility.How to install chromix-too
Install the extension on your Chrome browser.
If not already installed, install the npm package manager. A general way to install it on Unix systems is by executing (with root permissions)
The npm tool can usually be installed using other well-known package managers, for example in Ubuntu you should be able to do
Install the
chromix-too
package via npmHow to reload a tab from terminal
First of all, start the server:
Now, using the
chromix-too
tool you can list all tabs with the corresponding identifiers in order to be able select the right tab.The result will be something like
As you can see, the first column shows a unique numeric identifier and the second column shows the tab title.
Now suppose you want to reload the second tab in the list, that is the one with identifier 136. You can do this by typing
Alternative tab selection
If you cannot use the numeric identifier to select a tab, there are several other ways. For example you can select tabs based on their titles or you can select pinned or unpinned tabs. See this link for help about tab selection and about the usage of Chromix-Too in general. As you can see in the tutorial, it is even possible to force a total reload without using the browser cache.
Benefits of this approach with respect to other approaches
The main benefit of using this approach with respect to other solutions shown in the other answers (including my previous answer( is that you can select and reload tabs in a very precise way (for example by using unique IDs) and without having to send keystrokes to the GUI and to focus windows, which may be uncomfortable. For example, if you are using your computer to type some text, the other scripts shown in the previous answers would change the focus and you may end up typing on browser windows accidentally. This can be avoided using this solution.
One liner which will focus the Chrome window and then reload the browser by sending Control+r: