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

穿精又带淫゛_ 提交于 2019-12-02 18:59:06
cwd

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.

I have a work around for when I'm running snippets a bunch of times on a site. I wrap my snippet code in a function and assign it to a global variable.

e.g.,

window.mySnippet = function (value) {   console.log(value.toUpperCase()); }; 

When I run this snippet I can now run

mySnippet('hello world');   -> "HELLO WORLD" 

You still have to run the snippet once to load it into memory, but it's better than nothing.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!