Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which file does Snippets of Chrome Dev Tool saved at?

As I know , personal data always be saved at profile path which can be find at chrome://version.

I added many snippets in my Chrome Dev Tool, and want to backup them .

But I cann't find a file that snippets data saved in under this path.

Does anyone knows ? Plz tell me . Thanks very much!

like image 335
duXing Avatar asked Sep 26 '13 10:09

duXing


1 Answers

Working solution on latest chromium (90.0):

On my ubuntu18, chromium snippets are saved under: ~/.config/chromium/Default/Preferences as a one-line json file.

The above and Bookmarks are the files I normally backup.

if you parse that Preferences json file you find the snippets at the following json path:

ROOT.devtools.preferences.scriptSnippets

that property's value need to be parsed again as json. then you get an array of {name,content} for all your snippets.

Note: I am using jq-1.6 for the commands below

To backup all snippetes into one json file:

jq .devtools.preferences.scriptSnippets ~/.config/chromium/Default/Preferences \
| jq '. | fromjson' > /tmp/backup.json

To backup all snippets into separate .js files

# Tested with jq-1.6
# The script converts json entries into lines of format 
# `filename[TAB]content-in-base64` and then 
# for each line creates the corresponding file 
# with the content decoded.

# Better be in a safe directory!!
mkdir /tmp/snippets-backup
cd /tmp/snippets-backup

jq .devtools.preferences.scriptSnippets ~/.config/chromium/Default/Preferences \
| jq '. | fromjson | .[]| [ .name, @base64 "\(.content)" ] | @tsv' -r \
| xargs -I{} /bin/bash -c 'file=$(echo "{}"|cut -f1); fileContent=$(echo "{}"|cut -f2); echo "$fileContent" | base64 -d > "${file}.js"'

About jq

jq is a great command-line tool to query and process JSON files. You can get it from stedolan.github.io/jq/.

like image 142
Marinos An Avatar answered Sep 20 '22 09:09

Marinos An