Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix chrome-out.log and chrome-err.log keep opening after browser closed #317

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions src/chrome-launcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ class Launcher {
this.fs.writeFileSync(this.pidFile, this.chromeProcess.pid.toString());
}

// handle process closed right after it started
this.chromeProcess.on('close', () => {
delete this.chromeProcess;
this.destroyTmp();
});

log.verbose(
'ChromeLauncher',
`Chrome running with pid ${this.chromeProcess.pid} on port ${this.port}.`);
Expand Down Expand Up @@ -401,11 +407,6 @@ class Launcher {
return;
}

this.chromeProcess.on('close', () => {
delete this.chromeProcess;
this.destroyTmp();
});

log.log('ChromeLauncher', `Killing Chrome instance ${this.chromeProcess.pid}`);
try {
if (isWindows) {
Expand All @@ -428,21 +429,22 @@ class Launcher {
}

destroyTmp() {
// close all opened files
if (this.outFile) {
this.fs.closeSync(this.outFile);
delete this.outFile;
}

// Only clean up the tmp dir if we created it.
if (this.userDataDir === undefined || this.opts.userDataDir !== undefined) {
return;
}

if (this.errFile) {
this.fs.closeSync(this.errFile);
delete this.errFile;
}

// Only clean up the tmp dir if we created it.
if (this.userDataDir === undefined || this.opts.userDataDir !== undefined) {
return;
}

// backwards support for node v12 + v14.14+
// https://nodejs.org/api/deprecations.html#DEP0147
const rmSync = this.fs.rmSync || this.fs.rmdirSync;
Expand Down