How to reload Google Chrome tab from terminal?

后端 未结 8 1984
心在旅途
心在旅途 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:48

    chrome-remote-reload requires remote debugging enabled, but works both on Linux and Windows.

    1. Download executable: https://github.com/Benoth/chrome-remote-reload/releases or build it from sources.
    2. Run Chrome(/Chromium/Iron... or possibly even Opera or Edge, but the last one uses --devtools-server-port instead) with --remote-debugging-port=9222 parameter to enable remote debugging (just remember to close all instances of browser beforehand).
    3. Run downloaded executable.
    0 讨论(0)
  • 2021-02-02 18:51

    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)

    #!/bin/bash
    
    BROWSER=google-chrome # Or BROWSER=firefox for the Firefox case
    TABNUM=$1
    TABTITLE=$2
    
    CUR_WID=$(xdotool getwindowfocus)
    
    for WID in $(xdotool search --onlyvisible --class $BROWSER)
    do
      xdotool windowactivate $WID
      xdotool key "ctrl+$TABNUM"
      # Or "alt+$TABNUM" for the Firefox case
      WIN_TITLE=$(xdotool getwindowname $WID)
      if [[ $WIN_TITLE = *"$TABTITLE"* ]]
      then
        xdotool key 'F5'
      fi
    done   
    xdotool windowactivate $CUR_WID
    

    After creating the file, make it executable, for example by typing:

    chmod +x tab_refresh.sh
    

    Finally, to use this script, you have to type something like:

    ./tab_refresh.sh TABNUM TABTITLE
    

    For example, say you want to update the 4th tab in a Google Chrome window where its 4th tab title contains the string foo.

    ./tab_refresh.sh 4 foo
    
    0 讨论(0)
提交回复
热议问题