This is a Mac-Specific set of instructions abridged from my Stack Overflow answer of the same question. I'm a Mac user, and this is a Gist for my own use, really, but if you're a Linux or a - gods help you - Windows user, you can find similar commands there, too, as well.
Snippets are stored in a sort of "metastorage" internal preferences within Chrome. They are stored, separately, for each Chrome profile present on the system. These are accessible from the file system (and can be copied directly to your pasteboard - on a Mac, specifically) with the following command:
echo "Available Chrome profiles:" && readarray -t profiles < <(find "$HOME/Library/Application Support/Google/Chrome/" -path '*/Profile */Preferences' | sort); PS3='Choose Chrome profile to copy snippets from: '; select PROFILE in "${profiles[@]}"; do cat "$PROFILE" | jq -r '.devtools.preferences."script-snippets"' | pbcopy && echo "Snippets copied from $PROFILE."; break; done
(NOTE: I'm not certain if systems with only a single profile still have the [...]/Google/Chrome/Profile #/Preferences path structure. It's wholly possible Chrome uses a [...]/Google/Chrome/Profile/Preferences (or even a [...]/Google/Chrome/Preferences) path when only a single profile exists on the machine, and the command below would need to be altered. If you happen to run this and this IS the case, please provide a comment, below, and, should you need, I'll provide a one-liner to facilitate copying in THAT scenario, too).
To access the browser's metastroage, you need to open a Devtools-on-Devtools window:
- Press
Command+Option+i(Ctrl+Shift+ion Windows) to open DevTools. - Make sure that the developer tools are undocked into a new window (
Command+Shift+d, typically, on a Mac). You can also manually undock it via the menu by clicking:
- Focus the now-detached Devtools window.
- Press
Command+Option+iagain on this new window.
That will open the DevTools on the DevTools.
- Open a DETACHED instance of Dev Tools (⌘⌥+I, ⌘⇧ + D)
- Focus that window.
- Execute the following code:
InspectorFrontendHost.getPreferences(_=>console.log(JSON.parse(_['script-snippets']).sort((a,b)=>a.name.toUpperCase() <= b.name.toUpperCase() ? -1 : 1)))
- This will yield an Array of Objects, something similar to this:
- Right-click the Array output, and click Copy Object
- Paste into safe storage of your choice.
- To import them back in, really all you need is a strigified Array of Objects in that same format.
- Presupposing a variable containing an array of objects named
mySnippets:
InspectorFrontendHost.setPreference("scriptSnippets", JSON.stringify(mySnippets))
To view the last 300 console entries in the form of an Array of Strings (["Entry1", "Entry2"])
JSON.parse(localStorage.getItem('console-history'));
Assuming an array of string named myEntries:
localStorage.setItem('console-history', JSON.stringify(myEntries));



