Improve error reporting when chrome fails to start

This patch starts throwing exception and dumping chromium stderr when
the browser fails to start.

References #33
This commit is contained in:
Andrey Lushnikov 2017-06-20 19:26:16 -07:00 committed by Pavel Feldman
parent 229edb6b9b
commit eb02af93b6

View File

@ -99,6 +99,8 @@ class Browser {
if (this._chromeProcess) if (this._chromeProcess)
return; return;
this._chromeProcess = childProcess.spawn(this._chromeExecutable, this._chromeArguments, {}); this._chromeProcess = childProcess.spawn(this._chromeExecutable, this._chromeArguments, {});
var stderr = '';
this._chromeProcess.stderr.on('data', data => stderr += data.toString('utf8'));
// Cleanup as processes exit. // Cleanup as processes exit.
process.on('exit', () => this._chromeProcess.kill()); process.on('exit', () => this._chromeProcess.kill());
this._chromeProcess.on('exit', () => { this._chromeProcess.on('exit', () => {
@ -106,7 +108,9 @@ class Browser {
removeRecursive(this._userDataDir); removeRecursive(this._userDataDir);
}); });
await waitForChromeResponsive(this._remoteDebuggingPort); await waitForChromeResponsive(this._remoteDebuggingPort, () => !this._terminated);
if (this._terminated)
throw new Error('Failed to launch chrome! ' + stderr);
} }
close() { close() {
@ -118,7 +122,7 @@ class Browser {
module.exports = Browser; module.exports = Browser;
function waitForChromeResponsive(remoteDebuggingPort) { function waitForChromeResponsive(remoteDebuggingPort, shouldWaitCallback) {
var fulfill; var fulfill;
var promise = new Promise(x => fulfill = x); var promise = new Promise(x => fulfill = x);
var options = { var options = {
@ -135,7 +139,12 @@ function waitForChromeResponsive(remoteDebuggingPort) {
var req = http.request(options, res => { var req = http.request(options, res => {
fulfill(); fulfill();
}); });
req.on('error', e => setTimeout(sendRequest, probeTimeout)); req.on('error', e => {
if (shouldWaitCallback())
setTimeout(sendRequest, probeTimeout);
else
fulfill();
});
req.end(); req.end();
} }
} }