Skip to content

Commit f575433

Browse files
committed
Cleanly close existing Chrom* on Windows
1 parent de25a12 commit f575433

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/interceptors/chromium-based-interceptors.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import {
1010
Browser,
1111
LaunchOptions
1212
} from '../browsers';
13-
import { delay, readFile, deleteFolder, listRunningProcesses } from '../util';
13+
import { delay, readFile, deleteFolder, listRunningProcesses, windowsClose } from '../util';
1414
import { HideWarningServer } from '../hide-warning-server';
1515
import { Interceptor } from '.';
1616
import { reportError } from '../error-tracking';
@@ -228,7 +228,12 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
228228
);
229229
}
230230

231-
process.kill(existingPid);
231+
if (process.platform === 'win32') {
232+
windowsClose(existingPid);
233+
} else {
234+
process.kill(existingPid);
235+
}
236+
232237
await delay(1000);
233238
}
234239

src/util.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,15 @@ export async function listRunningProcesses(): Promise<Array<Proc>> {
167167
}
168168
}
169169

170+
// Cleanly close (simulate closing the main window) on a specific windows process
171+
export async function windowsClose(pid: number) {
172+
await spawnToResult('taskkill', [
173+
'/pid', pid.toString(),
174+
]);
175+
}
176+
177+
// Harshly kill a windows process by some WMIC matching string e.g.
178+
// "processId=..." or "CommandLine Like '%...%'"
170179
export async function windowsKill(processMatcher: string) {
171180
await spawnToResult('wmic', [
172181
'Path', 'win32_process',

0 commit comments

Comments
 (0)