From eb02af93b6d7516a242aec74b99a104c29c832e6 Mon Sep 17 00:00:00 2001 From: Andrey Lushnikov Date: Tue, 20 Jun 2017 19:26:16 -0700 Subject: [PATCH] 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 --- lib/Browser.js | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/Browser.js b/lib/Browser.js index 7ed797813ca..e6452462706 100644 --- a/lib/Browser.js +++ b/lib/Browser.js @@ -99,6 +99,8 @@ class Browser { if (this._chromeProcess) return; this._chromeProcess = childProcess.spawn(this._chromeExecutable, this._chromeArguments, {}); + var stderr = ''; + this._chromeProcess.stderr.on('data', data => stderr += data.toString('utf8')); // Cleanup as processes exit. process.on('exit', () => this._chromeProcess.kill()); this._chromeProcess.on('exit', () => { @@ -106,7 +108,9 @@ class Browser { 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() { @@ -118,7 +122,7 @@ class Browser { module.exports = Browser; -function waitForChromeResponsive(remoteDebuggingPort) { +function waitForChromeResponsive(remoteDebuggingPort, shouldWaitCallback) { var fulfill; var promise = new Promise(x => fulfill = x); var options = { @@ -135,7 +139,12 @@ function waitForChromeResponsive(remoteDebuggingPort) { var req = http.request(options, res => { fulfill(); }); - req.on('error', e => setTimeout(sendRequest, probeTimeout)); + req.on('error', e => { + if (shouldWaitCallback()) + setTimeout(sendRequest, probeTimeout); + else + fulfill(); + }); req.end(); } }