Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Run javascript file from the workspace in chrome developer tools

Is it possible to run a newly created JavaScript file in a local workspace in the chrome developer tools console?

The workflow I'm trying to achieve is the one shown in this image:

enter image description here

I want to be able to create a new file in my workspace, run (or require or whatever) the file and be able to use it's functions and variables in the chrome developer console.

If I'm correct, this means running the script within the context of the webpage and adding the methods and variables to the window object?

Is their a way this can be done?

like image 548
arnoutaertgeerts Avatar asked Jan 15 '15 08:01

arnoutaertgeerts


2 Answers

I could not find an automatic way to add a local file into the DOM context. The best solution I found so far:

  • Open your local workspace and the right file
  • Press CTRL + a (Select all)
  • Press CTRL + SHIFT + e (alternative: Right click with the mouse on the selected text and click on "Evaluate in Console")

Well, this is not much better than copy&paste but spares a few key presses/mouse clicks.

like image 101
Trendfischer Avatar answered Oct 17 '22 17:10

Trendfischer


You can create a plain html file like this with your javascript file in the script tag.

enter image description here

Then you should be able to get all your methods in the developer console.

like image 1
Raj Kumar Avatar answered Oct 17 '22 17:10

Raj Kumar