From 7c8b46dd4a4ce11ad6fd1c436416cdbd448c1b73 Mon Sep 17 00:00:00 2001 From: Puja Jagani Date: Mon, 16 Sep 2024 15:18:17 +0530 Subject: [PATCH] [js] Close CDP websocket connection on driver.quit (#14501) --- javascript/node/selenium-webdriver/lib/webdriver.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/javascript/node/selenium-webdriver/lib/webdriver.js b/javascript/node/selenium-webdriver/lib/webdriver.js index ac4e2e1a6a432..6317a4fa05dba 100644 --- a/javascript/node/selenium-webdriver/lib/webdriver.js +++ b/javascript/node/selenium-webdriver/lib/webdriver.js @@ -784,6 +784,14 @@ class WebDriver { if (this.onQuit_) { return this.onQuit_.call(void 0) } + + // Close the websocket connection on quit + // If the websocket connection is not closed, + // and we are running CDP sessions against the Selenium Grid, + // the node process never exits since the websocket connection is open until the Grid is shutdown. + if (this._wsConnection !== undefined) { + this._wsConnection.close() + } }) }