Web Inspector ReferenceConsole Snippets
Console Snippets are JavaScript resources created in and persisted by Web Inspector for evaluating pre-written JavaScript code in the Console, instead of having to write the (same) JavaScript code over and over (or copying and pasting).
Console Snippets are uniquely identified by name, which must be provided when creating them.
Creating Console Snippets
Console Snippets can be created by:
- selecting Console Snippet… when creating a resource
- selecting Create Console Snippet… in the context menu shown when clicking on the [Run Console Snippet…] in the Console Tab and Split Console
Once at least one Console Snippet has been created, a new Console Snippets section will appear in the Navigation Sidebar of the Sources Tab. This section also has a [Create Console Snippet].
All capabilities of the Console Command Line API are available inside Console Snippets.
Any modifications to the Console Snippet are automatically saved and will be used the next time the Console Snippet is run.
Running Console Snippets
Running a Console Snippet is as easy as:
- clicking on the [Run] that appears on hover in the Sources Tab
- pressing
space
orenter
when selected in the Navigation Sidebar of the Sources Tab - selecting it in the context menu shown when clicking on the [Run Console Snippet…] in the Console Tab and Split Console
The JavaScript contents of the Console Snippet will be evaluated in the Console as though they were typed into the Console Prompt, meaning they will use the currently selected execution context. Any results will appear in the Console right after the name of the Console Snippet.