Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome: Call Javascript function from (system) command line?

I need to call a Javascript function from a website running in Google Chrome / Chromium from the command line.

Is there any possibility to get access over the developer tools from outside via command line? Is there an extension I could use to execute code?

The most convenient way would be to have access to the Chrome developer console from the command line.

Edit:

To make it more clear: Let’s say the website I’m on has this function defined:

function hello() {
  alert("hello");
}

I would like to call this function, but I don’t have access to the developer tools in Chrome. I can only access the Mac OS X Terminal (via SSH). It’s a setup in a gallery without keyboard. Some kind of pipe may be needed.

like image 756
Pwdr Avatar asked Sep 30 '15 17:09

Pwdr


People also ask

How do you call JavaScript in Chrome?

In that case, you can open a Sources tab, locate your . js file, place a breakpoint anywhere at the bottom of the outer function (you might need to refresh a page after that if the code have already been run) and call yourFunction() in console. Also, while at breakpoint you may do something like window.

How do I run a JavaScript file in Chrome console?

To run the JavaScript code you have written, you can press Ctrl + Enter on the keyword. If you have some console statements in your code, those things will be displayed inside the console window at the bottom of the screen, as shown in the above image.

How do I use console commands in Google Chrome?

To open the Command Menu: Press Control + Shift + P (Windows / Linux) or Command + Shift + P (Mac). Click. Customize and control DevTools and then select Run command.


1 Answers

After some more research I found crconsole, which can be used to execute code in Google Chrome.

Chrome has to be started like this:
open -a "Google Chrome" --args --remote-debugging-port=9222

like image 166
Pwdr Avatar answered Sep 27 '22 23:09

Pwdr