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() + } }) }