Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running code snippets from Google Chrome console command line, using (experimental) code snippets feature?

Reference:

Using the new code snippets feature in google chrome

I am using the code snippets in google chrome, so say I have a snippet file. check_consistency.js

Is there an api or a global object through which we can run the snippet directly from the command line, something like:

  window.runSnippet('check_consistency.js') 

or maybe call methods defined in the snippet directly.

like image 790
sbr Avatar asked Mar 22 '13 20:03

sbr


People also ask

Does Google Chrome have snippet?

Press Control+Shift+P or Command+Shift+P (Mac) to open the Command Menu. Start typing Snippets , select Show Snippets, and then press Enter to run the command.

How do I export a snippet from Chrome?

To export a snippet, launch Dev Tools of the Dev Tools. That is, launch Chrome Dev Tools in a separate window ( do not dock with the web page). Select the Dev Tools window and use Ctrl+ Shift + I (Windows) / Cmd + Option + I (Mac) again. It launches a second dev tools window.


1 Answers

Workflow Tip 1

I also want to see this functionality added. Meanwhile, perhaps try opening the Sources where (as you know) you can select a snippet and right click it to run it. You may or may not know that you can tap Esc on this page in order to show the console at the same time as your snippets:

Workflow Tip 2

The snippets documentation also mentions

The ability to quickly locate a specific file can be essential to a developer's workflow. The DevTools allow you to search across all script, stylesheet and snippet files using the following shortcuts:

Ctrl + O (Windows, Linux)
Cmd + O (Mac OSX)

which will work regardless of the panel you are currently in.

...and...

A keyboard shortcut is also available for easily executing a snippet - just select your snippet then use Ctrl/Cmd + Enter to run it. This replicates the behavior of the Run (>) button - currently in the Sources console, but which will be moving into the debugger control in the near future.

What this means is that while in the console you can press Ctrl/Cmd+O to quickly select your snippet, and then press Cmd/Control+Enter to run it.

like image 188
cwd Avatar answered Sep 22 '22 08:09

cwd