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 que
If some of these aren't working out for you, I was looking for a similar thing for vivaldi, and managed to do it combining some things here and others in another post
xdotool windowactivate $(xdotool search --class vivaldi | tail -1) key ctrl+r windowactivate $(xdotool getactivewindow)
you can add other key - keyvalue combinations after the first one
One liner which will focus the Chrome window and then reload the browser by sending Control+r:
xdotool search --onlyvisible --class Chrome windowfocus key ctrl+r
Looks like user2974830's answer is using some incorrect (perhaps old) syntax for xdotool. --search
is supposed to be just search
(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.
echo "$(date --rfc-3339=seconds) Refresh: $FILE"
CUR_WID=$(xdotool getwindowfocus)
#gets the first $BROWSER window, if you have more than one
#$BROWSER window open, it might not refresh the right one,
#as an alternative you can search by the window/html title
WID=$(xdotool search --onlyvisible --class $BROWSER|head -1)
#TITLE="window/html file title"
#WID=$(xdotool search --title "$TITLE"|head -1)
xdotool windowactivate $WID
xdotool key 'ctrl+r'
xdotool windowactivate $CUR_WID
I saved it to a file called reload-chrome-nix
and I run find . -type f | entr ./reload-chrome-nix
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.
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)
curl -L https://www.npmjs.com/install.sh | sh
The npm tool can usually be installed using other well-known package managers, for example in Ubuntu you should be able to do
sudo apt-get install npm
Install the chromix-too
package via npm
sudo npm install -g chromix-too
First of all, start the server:
chromix-too-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.
chromix-too ls
The result will be something like
35 The foo bar website
136 https://another.website.foo/
142 https://another.one.bar/
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
chromix-too reload 136
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.
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.
sudo apt-get update
sudo apt-get install xdotool
DISPLAY=:0 xdotool key F5
That's all you need.
Probably this could be a (the easiest) solution for your problem
xdotool key --windowid "$(xdotool --search --class Chrome | head -n 1)" F5
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