code-snippets icon indicating copy to clipboard operation
code-snippets copied to clipboard

snippets are no longer available via localStorage

Open paulirish opened this issue 10 years ago • 6 comments

We made snippets (among other settings) available from incognito. I think this change landed in Chrome stable around 46/47 or so.

As a result, they are no longer available in localStorage. Here's the new technique. These are run from a devtools-on-devtools window.

getting snippets

InspectorFrontendHost.getPreferences(_ => console.log(JSON.parse(_.scriptSnippets)))

setting snippets

InspectorFrontendHost.setPreference("scriptSnippets", JSON.stringify(yourSnippets))

FWIW, InspectorFrontendHost.getPreferences will return everything that has migrated to the incognito-available settings (most things), while a few items (like breakpoints) remain in the devtools' localStorage

Tagging a few other issues that use this technique:

  • #6
  • https://github.com/bgrins/devtools-snippets/issues/28
  • https://github.com/bgrins/devtools-snippets/pull/35
  • http://stackoverflow.com/questions/19025718/which-file-does-snippets-of-chrome-dev-tool-saved-at

paulirish avatar Jan 25 '16 19:01 paulirish

Thanks for the info, helped me tremendously.

I have tried updating the update-code-snippets and started to work on a gui manager script. Seems to work ok so far:

https://github.com/soundyogi/code-snippets/blob/master/update-code-snippets.js https://gist.github.com/soundyogi/03df95505604c8351212

I will file a PR when I added support for the old version aswell.

soundyogi avatar Jan 26 '16 18:01 soundyogi

cool, will update the updater snippet at some point

bahmutov avatar Feb 29 '16 21:02 bahmutov

It seems there is no way to map snippets to localSystem. Is mapping snippets to local file system a valid use case or is there something obvious I am missing?

cole-gillespie avatar Aug 14 '17 01:08 cole-gillespie

Not that I know of, I wrote a little module "require" that required some snippets before others but even for that you need to Inspect the Inspector ... I guess snippets are to sandboxed for local mapping?

soundyogi avatar Aug 14 '17 10:08 soundyogi

now InspectorFrontendHost is gone as well

Commandtechno avatar Sep 23 '21 16:09 Commandtechno

is there any way of importing snippets now. InspectorFrontendHost is not defined now

Vijaythepro avatar Mar 22 '24 17:03 Vijaythepro