diff --git a/lib/Launcher.js b/lib/Launcher.js index feac7173..c78e025b 100644 --- a/lib/Launcher.js +++ b/lib/Launcher.js @@ -85,13 +85,12 @@ class Launcher { } // Cleanup as processes exit. - let killed = false; - process.once('exit', killChrome); if (temporaryUserDataDir) chromeProcess.once('close', () => removeSync(temporaryUserDataDir)); + const listeners = [ helper.addEventListener(process, 'exit', killChrome) ]; if (options.handleSIGINT !== false) - process.once('SIGINT', killChrome); + listeners.push(helper.addEventListener(process, 'SIGINT', killChrome)); try { const connectionDelay = options.slowMo || 0; @@ -104,9 +103,7 @@ class Launcher { } function killChrome() { - if (killed) - return; - killed = true; + helper.removeEventListeners(listeners); if (process.platform === 'win32') childProcess.execSync(`taskkill /pid ${chromeProcess.pid} /T /F`); else