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:

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.


Updated for Safari Technology Preview 156. Try it out for the latest Web Inspector features, including all of the above and more.


Written November 2, 2022 by Devin Rousso

Last updated February 16, 2023 by Jon Davis