以编程方式使用Node.js启动和终止Web浏览器

时间:2015-06-04 14:38:13

标签: javascript node.js browser

如何使用Node.js以编程方式启动和终止Web浏览器?

像这样的伪代码:

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
});