8

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.

16
  • Your mean command line (CMD) in windows? why you not use google console? Commented Sep 30, 2015 at 17:29
  • 2
    What are the downvotes for? Maybe it's an odd question, but I wouldn't call it unclear or lacking research effort. It could benefit, greatly, from a "why." Commented Sep 30, 2015 at 17:30
  • @Cerbrus There are all sorts of options when launching Chrome from terminal. It's possible that's really what OP wants. Also note that "terminal" is a tag here. Commented Sep 30, 2015 at 17:30
  • I am talking about Terminal in Mac OS X. Basically I would like the code I enter there, e.g chrome-pipe alert("hello") to be executed in the developer tools console (in this case resulting in a popup). Commented Sep 30, 2015 at 17:31
  • 1
    @Pwdr: Why? You seem to have the dev console open already. Why not enter your code there? Commented Sep 30, 2015 at 17:32

2 Answers 2

6

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

Sign up to request clarification or add additional context in comments.

Comments

5

The command line utility chrome-cli can do this.

Using your code example:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.