How to reload Google Chrome tab from terminal?

后端 未结 8 1983
心在旅途
心在旅途 2021-02-02 17:57

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

相关标签:
8条回答
  • 2021-02-02 18:30

    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

    0 讨论(0)
  • 2021-02-02 18:31

    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
    
    0 讨论(0)
  • 2021-02-02 18:35

    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

    0 讨论(0)
  • 2021-02-02 18:38

    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

    1. Install the extension on your Chrome browser.

    2. 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
      
    3. Install the chromix-toopackage via npm

      sudo npm install -g chromix-too
      

    How to reload a tab from terminal

    1. First of all, start the server:

      chromix-too-server
      
    2. 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.

    3. 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
      

    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.

    0 讨论(0)
  • 2021-02-02 18:43
    sudo apt-get update
    
    sudo apt-get install xdotool
    
    DISPLAY=:0 xdotool key F5
    

    That's all you need.

    0 讨论(0)
  • 2021-02-02 18:45

    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

    0 讨论(0)
提交回复
热议问题