2

How can I programmatically both start and kill a web browser using Node.js?

Pseudo-ish code like so:

var spawn = require('child_process').spawn;

// This opens a browser and returns control to terminal, but optimally
// the process should run in the foreground and exit on ctrl-c.
spawn('open', ['http://www.stackoverflow.com']);

process.on('SIGINT', function() {
  // Kill the opened browser here
});
5
  • 1
    You're going to have to show the relevant code if you wish to get answers here. Commented Jun 4, 2015 at 14:40
  • It sounds like you're asking for a suggestion on which to library to use, which is not what StackOverflow is for Commented Jun 4, 2015 at 14:43
  • If you are looking for a package to do this like Karma Test Runner does, Juan Mendes is correct. If you are trying to implement similar behavior in your own code, Jonast92 is correct (and Karma Test Runner's code seems like a good place to look for clues how to go about it). Please clarify which is the case. Commented Jun 4, 2015 at 15:14
  • Check stackoverflow.com/questions/14031763/… for how to do things on ctrl-c. Commented Jun 4, 2015 at 15:35
  • Thanks for your comments. I've removed references to other libs from the question, and added some code that hopefully clarify things. Commented Jun 4, 2015 at 16:48

1 Answer 1

-1

You can use "spawn"

https://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options

Also, reference: https://stackoverflow.com/a/16099450/4130451

To Kill: https://nodejs.org/api/child_process.html#child_process_child_kill_signal

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

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.