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
});
Claudijo
  • 1,321
  • 1
  • 10
  • 15
  • 1
    You're going to have to show the relevant code if you wish to get answers here. – Jonast92 Jun 04 '15 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 – Ruan Mendes Jun 04 '15 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. – J0e3gan Jun 04 '15 at 15:14
  • Check http://stackoverflow.com/questions/14031763/doing-a-cleanup-action-just-before-node-js-exits for how to do things on `ctrl-c`. – m4ktub Jun 04 '15 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. – Claudijo Jun 04 '15 at 16:48