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

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

Is it possible to access the developer tools from the outside through the command line? Is there an extension that I could use to execute code?

The most convenient way is to access the Chrome Developer Console from the command line.

Edit:

To make this clearer: Assume that this function is defined on the Im on site:

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

I would call this feature, but I do not have access to the developer tools in Chrome. I can only access the Mac OS X terminal (via SSH). Its setting in the gallery without a keyboard. You may need some kind of pipe.

+5
source share
2 answers

After some more research, I found a crconsole that you can use to execute code in Google Chrome.

Chrome should be launched as follows:
open -a "Google Chrome" --args --remote-debugging-port=9222

+2
source

The chrome-cli command line utility can do this.

Using the sample code:

 chrome-cli execute '(function hello() { alert("hello"); }())' 
+1
source

Source: https://habr.com/ru/post/1232643/


All Articles