mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix(Launcher): Launcher should handle chrome process errors (#863)
Fixes #750
This commit is contained in:
parent
cb280c526d
commit
c46c41d89c
@ -116,16 +116,13 @@ class Launcher {
|
|||||||
*/
|
*/
|
||||||
function killChrome() {
|
function killChrome() {
|
||||||
helper.removeEventListeners(listeners);
|
helper.removeEventListeners(listeners);
|
||||||
|
if (chromeProcess.pid) {
|
||||||
if (temporaryUserDataDir) {
|
if (temporaryUserDataDir) {
|
||||||
// Force kill chrome.
|
// Force kill chrome.
|
||||||
if (process.platform === 'win32')
|
if (process.platform === 'win32')
|
||||||
childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`);
|
childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`);
|
||||||
else
|
else
|
||||||
process.kill(-chromeProcess.pid, 'SIGKILL');
|
process.kill(-chromeProcess.pid, 'SIGKILL');
|
||||||
// Attempt to remove temporary profile directory to avoid littering.
|
|
||||||
try {
|
|
||||||
removeSync(temporaryUserDataDir);
|
|
||||||
} catch (e) { }
|
|
||||||
} else {
|
} else {
|
||||||
// Terminate chrome gracefully.
|
// Terminate chrome gracefully.
|
||||||
if (process.platform === 'win32')
|
if (process.platform === 'win32')
|
||||||
@ -133,6 +130,13 @@ class Launcher {
|
|||||||
else
|
else
|
||||||
process.kill(-chromeProcess.pid, 'SIGTERM');
|
process.kill(-chromeProcess.pid, 'SIGTERM');
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (temporaryUserDataDir) {
|
||||||
|
// Attempt to remove temporary profile directory to avoid littering.
|
||||||
|
try {
|
||||||
|
removeSync(temporaryUserDataDir);
|
||||||
|
} catch (e) { }
|
||||||
|
}
|
||||||
return waitForChromeToClose;
|
return waitForChromeToClose;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -166,15 +170,19 @@ function waitForWSEndpoint(chromeProcess, timeout) {
|
|||||||
let stderr = '';
|
let stderr = '';
|
||||||
const listeners = [
|
const listeners = [
|
||||||
helper.addEventListener(rl, 'line', onLine),
|
helper.addEventListener(rl, 'line', onLine),
|
||||||
helper.addEventListener(rl, 'close', onClose),
|
helper.addEventListener(rl, 'close', () => onClose()),
|
||||||
helper.addEventListener(chromeProcess, 'exit', onClose)
|
helper.addEventListener(chromeProcess, 'exit', () => onClose()),
|
||||||
|
helper.addEventListener(chromeProcess, 'error', error => onClose(error))
|
||||||
];
|
];
|
||||||
const timeoutId = timeout ? setTimeout(onTimeout, timeout) : 0;
|
const timeoutId = timeout ? setTimeout(onTimeout, timeout) : 0;
|
||||||
|
|
||||||
function onClose() {
|
/**
|
||||||
|
* @param {!Error=} error
|
||||||
|
*/
|
||||||
|
function onClose(error) {
|
||||||
cleanup();
|
cleanup();
|
||||||
reject(new Error([
|
reject(new Error([
|
||||||
'Failed to launch chrome!',
|
'Failed to launch chrome!' + (error ? ' ' + error.message : ''),
|
||||||
stderr,
|
stderr,
|
||||||
'',
|
'',
|
||||||
'TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md',
|
'TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md',
|
||||||
|
Loading…
Reference in New Issue
Block a user