Skip to content

Instantly share code, notes, and snippets.

@mluis7
Last active July 2, 2018 01:14
Show Gist options
  • Save mluis7/bc7bdf7f4a2fb8e35c3b113123a674bd to your computer and use it in GitHub Desktop.
Save mluis7/bc7bdf7f4a2fb8e35c3b113123a674bd to your computer and use it in GitHub Desktop.
Automate keystrokes to set chrome with persistent logs on Network tab.
Automate keystrokes to open URL in Chrome with persistent logs on Network tab.
Tested with Chrome 66.
A funny workaround to save time while using Chrome dev tools:
* Make sure xdotool is installed
* Launch chrome
* Put the code below in a bash script chrome_auto.sh to send all the keys to: open a tab, dev tools, settings, set 'persistent logs', type the URL and hit enter.
#!/bin/bash
url="https://www.stackoverflow.com"
if [ -n "$1" ]; then
url="$1"
fi
# find chrome window id
wid=$(xdotool search --class Chromium | tail -n1)
# build tab key sequence to set 'persistent logs'
tabkeys=$(for i in {1..24}; do t+="Tab ";done ;echo "$t space")
# base xdotool command
cmd="xdotool windowactivate --sync $wid"
# make chrome dance :-p
$cmd key ctrl+t
$cmd key F12
sleep 1
# open settings, move to desired option and select it
$cmd key F1 $tabkeys
sleep 1
# move cursor to URL box and type URL
$cmd key F6 type "$url"
$cmd key Return
Use the script as
./chrome_auto.sh "https://stackoverflow.com/questions/45133659"
Also, chrome can be launched with dev tools open for every tab. If this is used, comment out the line with key F12
chromium --auto-open-devtools-for-tabs > /dev/null 2>&1 &
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment