Skip to content

Instantly share code, notes, and snippets.

@amacgregor
Forked from eugenehp/node-chrome
Created July 13, 2014 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amacgregor/61db2f5be10b08b00f42 to your computer and use it in GitHub Desktop.
Save amacgregor/61db2f5be10b08b00f42 to your computer and use it in GitHub Desktop.
var express = require('express');
var cp = require('child_process');
var app = express.createServer();
var chrome_count = 0;
app.get('/', function(req, res){
startChrome(chrome_count++,9222,function chromeStared(err,id,chrome){
res.send('Chrome '+id+' Started\r\n');
console.log('Simulating data parsing');
setTimeout(function(){
console.log('Shutdown chrome '+id);
chrome.kill('SIGHUP');
},10000);
});
});
var port = 3000;
app.listen(port);
console.log('Server is listening on port ' + port);
function startChrome(id,port,callback){
var terminal = cp.spawn('bash');
var chrome = {};
terminal.on('exit', function (code) {
//console.log('child process exited with code ' + code);
console.log('Starting chrome');
chrome = cp.spawn('/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome',[
'--remote-debugging-port='+port,
'--user-data-dir=/Volumes/DATA/repos/scrapper/userdata',
'http://www.patrickhyundai.com/browse-new-hyundais.aspx'
]);
callback(null,id,chrome);
});
setTimeout(function() {
console.log('Sending stdin to terminal');
//terminal.stdin.write('echo "Hello $USER"');
terminal.stdin.write('rm -rf /Volumes/DATA/repos/scrapper/userdata'+'\n');
terminal.stdin.write('mkdir /Volumes/DATA/repos/scrapper/userdata'+'\n');
terminal.stdin.write('touch "/Volumes/DATA/repos/scrapper/userdata/First Run"'+'\n');
terminal.stdin.write('chmod 777 "/Volumes/DATA/repos/scrapper/userdata/First Run"'+'\n');
terminal.stdin.end();
}, 1000);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment