Which file does Snippets of Chrome Dev Tool saved at?

前端 未结 5 1689
失恋的感觉
失恋的感觉 2021-01-02 08:29

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

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-02 09:05

    Working solution on latest chromium (81):

    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.

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

提交回复
热议问题