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.
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.
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.
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.
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
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