properly cleanup exit process listener as browser closes

This commit is contained in:
Andrey Lushnikov 2017-07-11 08:11:16 -07:00
parent b6d0ebfbf2
commit d120e7e426

View File

@ -112,9 +112,11 @@ class Browser {
let stderr = '';
this._chromeProcess.stderr.on('data', data => stderr += data.toString('utf8'));
// Cleanup as processes exit.
process.on('exit', () => this._chromeProcess.kill());
const onProcessExit = () => this._chromeProcess.kill();
process.on('exit', onProcessExit);
this._chromeProcess.on('exit', () => {
this._terminated = true;
process.removeListener('exit', onProcessExit);
removeRecursive(this._userDataDir);
});
this._chromeProcess.stderr.pipe(this.stderr);