Kill Chrome quickly on Windows (#488)
This patch start killing chrome on windows with taskkill command.
This commit is contained in:
parent
a00ba6a3d9
commit
ac109dba6d
@ -82,26 +82,31 @@ class Launcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Cleanup as processes exit.
|
// Cleanup as processes exit.
|
||||||
const listeners = [
|
let killed = false;
|
||||||
helper.addEventListener(process, 'exit', killChromeAndCleanup),
|
process.once('exit', killChrome);
|
||||||
helper.addEventListener(chromeProcess, 'exit', killChromeAndCleanup),
|
chromeProcess.once('close', () => removeSync(userDataDir));
|
||||||
];
|
|
||||||
if (options.handleSIGINT !== false)
|
if (options.handleSIGINT !== false)
|
||||||
listeners.push(helper.addEventListener(process, 'SIGINT', killChromeAndCleanup));
|
process.once('SIGINT', killChrome);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const connectionDelay = options.slowMo || 0;
|
const connectionDelay = options.slowMo || 0;
|
||||||
const browserWSEndpoint = await waitForWSEndpoint(chromeProcess, options.timeout || 30 * 1000);
|
const browserWSEndpoint = await waitForWSEndpoint(chromeProcess, options.timeout || 30 * 1000);
|
||||||
const connection = await Connection.create(browserWSEndpoint, connectionDelay);
|
const connection = await Connection.create(browserWSEndpoint, connectionDelay);
|
||||||
return new Browser(connection, !!options.ignoreHTTPSErrors, killChromeAndCleanup);
|
return new Browser(connection, !!options.ignoreHTTPSErrors, killChrome);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
killChromeAndCleanup();
|
killChrome();
|
||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
function killChromeAndCleanup() {
|
function killChrome() {
|
||||||
helper.removeEventListeners(listeners);
|
if (killed)
|
||||||
chromeProcess.kill('SIGKILL');
|
return;
|
||||||
removeSync(userDataDir);
|
killed = true;
|
||||||
|
if (process.platform === 'win32')
|
||||||
|
childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`);
|
||||||
|
else
|
||||||
|
chromeProcess.kill('SIGKILL');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user