fix(Launcher): Launcher should handle chrome process errors (#863)

Fixes #750
This commit is contained in:
Andrey Lushnikov 2017-09-29 12:21:24 -07:00 committed by GitHub
parent cb280c526d
commit c46c41d89c

View File

@ -116,22 +116,26 @@ class Launcher {
*/
function killChrome() {
helper.removeEventListeners(listeners);
if (chromeProcess.pid) {
if (temporaryUserDataDir) {
// Force kill chrome.
if (process.platform === 'win32')
childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`);
else
process.kill(-chromeProcess.pid, 'SIGKILL');
} else {
// Terminate chrome gracefully.
if (process.platform === 'win32')
childProcess.execSync(`taskkill /pid ${chromeProcess.pid}`);
else
process.kill(-chromeProcess.pid, 'SIGTERM');
}
}
if (temporaryUserDataDir) {
// Force kill chrome.
if (process.platform === 'win32')
childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`);
else
process.kill(-chromeProcess.pid, 'SIGKILL');
// Attempt to remove temporary profile directory to avoid littering.
try {
removeSync(temporaryUserDataDir);
} catch (e) { }
} else {
// Terminate chrome gracefully.
if (process.platform === 'win32')
childProcess.execSync(`taskkill /pid ${chromeProcess.pid}`);
else
process.kill(-chromeProcess.pid, 'SIGTERM');
}
return waitForChromeToClose;
}
@ -166,15 +170,19 @@ function waitForWSEndpoint(chromeProcess, timeout) {
let stderr = '';
const listeners = [
helper.addEventListener(rl, 'line', onLine),
helper.addEventListener(rl, 'close', onClose),
helper.addEventListener(chromeProcess, 'exit', onClose)
helper.addEventListener(rl, 'close', () => onClose()),
helper.addEventListener(chromeProcess, 'exit', () => onClose()),
helper.addEventListener(chromeProcess, 'error', error => onClose(error))
];
const timeoutId = timeout ? setTimeout(onTimeout, timeout) : 0;
function onClose() {
/**
* @param {!Error=} error
*/
function onClose(error) {
cleanup();
reject(new Error([
'Failed to launch chrome!',
'Failed to launch chrome!' + (error ? ' ' + error.message : ''),
stderr,
'',
'TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md',