From fc94a28778cfdb3cb8bcd882af3ebcdacf85c94e Mon Sep 17 00:00:00 2001 From: Henrik Skupin Date: Mon, 15 Nov 2021 12:52:09 +0100 Subject: [PATCH] fix: try to remove the temporary user data directory after the process has been killed (#7761) --- src/node/BrowserRunner.ts | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/node/BrowserRunner.ts b/src/node/BrowserRunner.ts index 4c4e3c2597c92..e4b4aaca9600e 100644 --- a/src/node/BrowserRunner.ts +++ b/src/node/BrowserRunner.ts @@ -180,13 +180,6 @@ export class BrowserRunner { } kill(): void { - // Attempt to remove temporary profile directory to avoid littering. - try { - if (this._isTempUserDataDir) { - removeFolder.sync(this._userDataDir); - } - } catch (error) {} - // If the process failed to launch (for example if the browser executable path // is invalid), then the process does not get a pid assigned. A call to // `proc.kill` would error, as the `pid` to-be-killed can not be found. @@ -199,6 +192,14 @@ export class BrowserRunner { ); } } + + // Attempt to remove temporary profile directory to avoid littering. + try { + if (this._isTempUserDataDir) { + removeFolder.sync(this._userDataDir); + } + } catch (error) {} + // Cleanup this listener last, as that makes sure the full callback runs. If we // perform this earlier, then the previous function calls would not happen. helper.removeEventListeners(this._listeners);