Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run my own script inside Chrome's debugger console?

I'm tired of re-typing the same commands into Chrome's developer console. Is it possible to load a script that I have saved on my local machine?

like image 895
Gareth Avatar asked Mar 10 '11 07:03

Gareth


People also ask

How do I run a code in inspect console?

Right-click in a webpage and then select Inspect. DevTools opens. Or, press Ctrl + Shift + J (Windows, Linux) or Command + Option + J (macOS), to directly open the DevTools console. If necessary, click in DevTools to give it focus, and then press Esc to open the Console.


2 Answers

If you're running developer tools on a file:// URL, you can do something like:

s = document.createElement('script'); 
s.src = 'file://path/to/script.js'; 
document.body.appendChild(s);

As a workaround you could also paste in your oft-repeated code snippet into the developer tools.

like image 175
Boris Smus Avatar answered Oct 04 '22 17:10

Boris Smus


As @PaulIrish pointed out in the comments Chrome's Snippets are their solution to this problem. This screenshot below shows were to find snippets within Chrome's developer tools as of this writing. To run a snippet right click on its entry in the snippet pane, pictured on the left, and select "Run":

enter image description here

like image 42
Grant Humphries Avatar answered Oct 04 '22 17:10

Grant Humphries