3

Today I wanted to export my snippets from chrome.

I found Information from 2013: https://github.com/bgrins/devtools-snippets/issues/28#issuecomment-27455522

I opened the DevTools -> to sperate Window -> Inspect the Devtools Itself

Then in Console:

->localStorage.scriptSnippets
undefined
->var stringifiedSnippets = localStorage.getItem('scriptSnippets');
undefined
->stringifiedSnippets
null

I tested Chrome 48 (windows), Chromium 45(ubuntu) and a Friends Chrome on his Macbook. How can I access my Snippets.

Has the API changed? Or am I making a mistake here. Thanks.

soundyogi
  • 369
  • 3
  • 15

3 Answers3

3

Yes, the internals have changed. Your code should change to the following:

InspectorFrontendHost.getPreferences(function(prefs) {
    console.log(prefs.scriptSnippets);
});

Note: This script shall be run in second depth Dev Tools window! Make sure that the developer tools are undocked into a new window. Then press Ctrl+Shift+i (Command+Option+i) to open DevTools of DevTools. In that second DevTools window, run the script above.

S.Serpooshan
  • 7,608
  • 4
  • 33
  • 61
Alexander Pavlov
  • 31,598
  • 5
  • 67
  • 93
1

For those who arrive here and find the accepted answer is no longer working, here is a way to access your snippets as of May 2022 Chrome 101.

  1. Type chrome://version/ on a free tab in your Chrome browser.
  2. Check the "Profile Path:" which should be something like /home/your_user/.config/google-chrome/Default for Ubuntu based OSs.
  3. Find the Preferences file under that path and open it in a text editor. It's a big and messy JSON file. If you are making a new install at a different machine with a fresh Chrome installation then you may just copy this whole Preferences file under the same location in the new machine and i think your Chrome installation should have all the snippets from the original. Otherwise...
  4. Search for (Ctrl+f) "scriptSnippets" property including the quotes.
  5. I believe the snippets are in the order they are created. So not alphabetical like you see them in the snippets list.
  6. My list ends with "scriptSnippets_lastIdentifier":"142" property which means I must have created 142 snippets so far, some removed some remaining.
  7. Copy everything starting from "scriptSnippets":"[... up to ...}]" excluding "scriptSnippets_lastIdentifier":"142" or search for the snippet of your interest by it's name and copy only that portion.
Redu
  • 25,060
  • 6
  • 56
  • 76
  • Lovely answer, as it opens the doorway to automation for sharing snippets within a team. – Holf Oct 10 '22 at 16:56
  • 1
    @Holf Yeah. Perhaps you don't even need to set up a local webserver and use Chrome DevTools itself for that purpose. [How to Use Chrome as a Local Web Server](https://www.linkedin.com/pulse/how-use-chrome-local-server-mohammad-althayabeh?trk=related_artice_How%20to%20use%20Chrome%20as%20a%20Local%20Web%20Server_article-card_title) – Redu Oct 10 '22 at 17:15
0
InspectorFrontendHost.getPreferences(function(prefs) {
    console.log(prefs.scriptSnippets);
});
This code works perfectly in chrome version 51.0.2704.103
Sreehari
  • 5,621
  • 2
  • 25
  • 59
tkowt
  • 185
  • 1
  • 13
  • I'm sorry. I can use InspectorFrontendHost class opening another inspector following the way explained by [this question](http://stackoverflow.com/questions/12291138/how-do-you-inspect-the-web-inspector-in-chrome) this topic is very nice for me thanks! – tkowt Jun 28 '16 at 05:25