Closed daviddias closed 7 months ago
One thing I've realized now is that apparently each launch
instance only works to effectively launch one browser (all the others next will exit will 1), so it has to be called like this for several browsers
var launcher = require( 'browser-launcher2' );
var instances = []
launcher(function(err, launch) {
if ( err ) {
return console.error( err );
}
launch( 'http://cksource.com/', 'chrome', function( err, instance ) {
if ( err ) {
return console.error( err );
}
console.log( 'Instance started with PID:', instance.pid );
instance.on( 'stop', function( code ) {
console.log( 'Instance stopped with exit code && pid', code , ' && ', instance.pid );
});
});
});
launcher(function(err, launch) {
if ( err ) {
return console.error( err );
}
launch( 'http://cksource.com/', 'chrome', function( err, instance ) {
if ( err ) {
return console.error( err );
}
console.log( 'Instance started with PID:', instance.pid );
instance.on( 'stop', function( code ) {
console.log( 'Instance stopped with exit code && pid', code , ' && ', instance.pid );
});
});
});
setTimeout(function(){console.log('Dying now')}, 5000);
Nevertheless, the browsers still close immediately, most of the times they don't even load the page
Instance started with PID: 77306
Instance stopped with exit code && pid 0 && 77306
Instance started with PID: 77312
Instance stopped with exit code && pid 0 && 77312
Hi, sorry for the late answer. Could you clarify on what OS this problem occurs?
It's on Mac OS X Yosemite
@diasdavid again sorry for the delay. I checked what's going on on Mac. So, the problem here is that in order to launch a browser the open
command is used and this is the actual child process (Firefox and PhantomJS are exceptions here - those are run using their own binaries). It also appears that in case you already had an instance of the browser opened (with the same user profile), the open
command stops immediately - that's why it appears the browser dies right after it's started, but you should still be able to stop the browser using instance.stop()
because it uses osascript
to stop it.
Please try closing a browser completely (Quit from context menu) and running the provided launch.js
example. This should keep running until you completely quit the browser. I'm still thinking of a better solution, but OSX is not my primary OS so a little help here would be appreciated :)
And regarding the latter issue - I can confirm that there are some problems on OSX with starting multiple instances of the same browser, but running two or more instances of different browsers should work fine (and honestly that was our initial goal). I still believe this could be worked out, though it would require using different profiles for each instance and I'm still not sure how to stop those...
Hi!
Following your example, I get exactly the same result, however, I want the browser process to die when I call the .stop() function, I'm sure there should be a way because the browser process is just dying instantly, but I can't figure out why, halp?
Thank you!