16

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?

Gareth
  • 3,502
  • 4
  • 20
  • 21
  • 2
    This is precisely what the upcoming Snippets support is all about: http://stackoverflow.com/questions/10470711/chrome-developer-tools-what-is-snippets-support – Paul Irish May 17 '12 at 16:34
  • check out this similar question: http://stackoverflow.com/questions/5282228/include-javascript-file-in-chrome-console – Andy Jun 11 '12 at 23:27

2 Answers2

17

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.

Roman Kagan
  • 10,440
  • 26
  • 86
  • 126
Boris Smus
  • 8,220
  • 2
  • 36
  • 33
8

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

Grant Humphries
  • 2,696
  • 2
  • 23
  • 24