Skip to content

Commit

Permalink
🐛 Always kill browser process when able to
Browse files Browse the repository at this point in the history
  • Loading branch information
wwilsman committed Feb 14, 2021
1 parent 1f8f5d9 commit 0968fff
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions packages/core/src/discovery/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,11 @@ export default class Browser extends EventEmitter {
this.#callbacks.clear();
this.pages.clear();

// no executable means the browser never launched
// an exit code means the browser has already closed
/* istanbul ignore next: sanity */
if (!this.executable || this.process.exitCode) return;

// attempt to close the browser gracefully
let closed = new Promise(resolve => {
this.process.on('exit', resolve);
/* istanbul ignore next: race condition paranoia */
if (!this.process || this.process.exitCode) resolve();
else this.process.on('exit', resolve);
});

/* istanbul ignore next:
Expand All @@ -137,18 +134,21 @@ export default class Browser extends EventEmitter {
});

// attempt to clean up the profile directory after closing
await closed.then(() => new Promise(resolve => {
rimraf(this.profile, error => {
/* istanbul ignore next:
* this might happen on some systems but ultimately it is a temp file */
if (error) {
this.log.debug('Could not clean up temporary browser profile directory.');
this.log.debug(error);
}

resolve();
});
}));
/* istanbul ignore else: sanity */
if (this.profile) {
await closed.then(() => new Promise(resolve => {
rimraf(this.profile, error => {
/* istanbul ignore next:
* this might happen on some systems but ultimately it is a temp file */
if (error) {
this.log.debug('Could not clean up temporary browser profile directory.');
this.log.debug(error);
}

resolve();
});
}));
}
}

async page({ meta }) {
Expand Down

0 comments on commit 0968fff

Please sign in to comment.