I would like to run a local javascript file in chrome console but do not want to copy and paste the code. I know there is a command I can run from terminal to open the file in a new chrome window/tab but cannot recall it nor find example of it on-line.
What command can I call from the terminal to open a .js file in a new chrome tab where I can then run it in console?
I don't think you can do exactly that. To run JS with having access to the console, you can either copy its source to the console or to the address/location bar (javascript:(js code here)
).
The simplest way I can think of to achieve your goal is to wrap the JS in an HTML file and call chrome with chrome -u file:///path/to/file.html
. Include the JS in a <script>
tag also with the file:/// protocol in the src
attribute to point to the local file or using a relative path.
When chrome opens, you should have access to functions/variables defined in your code as global variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With