javascriptgoogle-chrome-devtoolsweb-inspector

Chrome Developer Tools: What is Snippets Support?


In the "Sources" tab of Chrome dev tools, there is a Snippets sub-tab:

The image shows a screenshot of a web browser's developer tools interface, specifically the 'Sources' tab. The tab is divided into several sections: Page, Workspace, Overrides, Content scripts, and Snippets. The focus is on the 'Snippets' section, which is highlighted with a red arrow pointing to it. There is a message below the tabs explaining that you can 'Save the JavaScript code you run often to run it again anytime,' and a link to 'Learn more' about this feature.

What can I use this for?


Solution

  • In short, snippets are a multi-line console, an iterative JS development workflow, and a persistent store for common debugging helpers.

    developers.google.com/chrome-developer-tools/docs/authoring-development-workflow#snippets

    Some of the use-cases Snippets can help with are:

    • Bookmarklets - all of your bookmarklets could be stored as snippets, especially those you may wish to edit.
    • Utilities - debugging helpers for interacting with the current page can be stored and debugged. A community-curated list of such utilities is available.
    • Debugging - Snippets offer a multi-line console with syntax-highlighting and persistance, making it convenience for debugging code that is more than a one-liner.
    • Monkey-patching code - code you wish to patch at runtime can be done through Snippets, although many times you can just live-edit code in the Sources tab.

    snippets screenshot

    Lastly, I've personally been collecting a few common snippets that you may include in your arsenal: github.com/paulirish/devtools-addons/wiki/Snippets


    To run snippets quickly, now you can do this. Ctrl-Shift-P for the "command palette", then backspace, and use a ! prefix, then type whichever snippet name you want to run.

    enter image description here