Skip to content

Commit 100c665

Browse files
committed
Try to close Chrome cleanly on exit on Windows
This doesn't yet work perfectly, looks like shutdown generally on Windows isn't very clean, but it should help when that does work better later.
1 parent d2573f5 commit 100c665

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/interceptors/chromium-based-interceptors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,16 @@ abstract class ExistingChromiumBasedInterceptor implements Interceptor {
283283
async deactivate(proxyPort: number | string) {
284284
if (this.isActive(proxyPort)) {
285285
const { browser } = this.activeBrowser!;
286+
287+
if (process.platform === 'win32') {
288+
// Try to cleanly close if we can, rather than killing Chrome directly:
289+
try {
290+
await windowsClose(browser!.pid)
291+
.then(() => waitForExit(browser!.pid));
292+
return;
293+
} catch (e) {} // If this fails/times out, kill like we do elsewhere:
294+
}
295+
286296
const exitPromise = new Promise((resolve) => browser!.process.once('close', resolve));
287297
browser!.stop();
288298
await exitPromise;

0 commit comments

Comments
 (0)