Skip to content

Commit cadcd27

Browse files
authored
Merge branch 'trunk' into dotnet-cdp-logs
2 parents 8c7cbc2 + 27ad7f4 commit cadcd27

File tree

1 file changed

+23
-15
lines changed

1 file changed

+23
-15
lines changed

javascript/node/selenium-webdriver/lib/webdriver.js

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,13 @@ class WebDriver {
789789
// If the websocket connection is not closed,
790790
// and we are running CDP sessions against the Selenium Grid,
791791
// the node process never exits since the websocket connection is open until the Grid is shutdown.
792-
if (this._wsConnection !== undefined) {
793-
this._wsConnection.close()
792+
if (this._cdpWsConnection !== undefined) {
793+
this._cdpWsConnection.close()
794+
}
795+
796+
// Close the BiDi websocket connection
797+
if (this._bidiConnection !== undefined) {
798+
this._bidiConnection.close()
794799
}
795800
})
796801
}
@@ -1241,18 +1246,18 @@ class WebDriver {
12411246
this._wsUrl = await this.getWsUrl(debuggerUrl, target, caps)
12421247
return new Promise((resolve, reject) => {
12431248
try {
1244-
this._wsConnection = new WebSocket(this._wsUrl.replace('localhost', '127.0.0.1'))
1245-
this._cdpConnection = new cdp.CdpConnection(this._wsConnection)
1249+
this._cdpWsConnection = new WebSocket(this._wsUrl.replace('localhost', '127.0.0.1'))
1250+
this._cdpConnection = new cdp.CdpConnection(this._cdpWsConnection)
12461251
} catch (err) {
12471252
reject(err)
12481253
return
12491254
}
12501255

1251-
this._wsConnection.on('open', async () => {
1256+
this._cdpWsConnection.on('open', async () => {
12521257
await this.getCdpTargets()
12531258
})
12541259

1255-
this._wsConnection.on('message', async (message) => {
1260+
this._cdpWsConnection.on('message', async (message) => {
12561261
const params = JSON.parse(message)
12571262
if (params.result) {
12581263
if (params.result.targetInfos) {
@@ -1273,7 +1278,7 @@ class WebDriver {
12731278
}
12741279
})
12751280

1276-
this._wsConnection.on('error', (error) => {
1281+
this._cdpWsConnection.on('error', (error) => {
12771282
reject(error)
12781283
})
12791284
})
@@ -1288,9 +1293,12 @@ class WebDriver {
12881293
* @returns {BIDI}
12891294
*/
12901295
async getBidi() {
1291-
const caps = await this.getCapabilities()
1292-
let WebSocketUrl = caps['map_'].get('webSocketUrl')
1293-
return new BIDI(WebSocketUrl.replace('localhost', '127.0.0.1'))
1296+
if (this._bidiConnection === undefined) {
1297+
const caps = await this.getCapabilities()
1298+
let WebSocketUrl = caps['map_'].get('webSocketUrl')
1299+
this._bidiConnection = new BIDI(WebSocketUrl.replace('localhost', '127.0.0.1'))
1300+
}
1301+
return this._bidiConnection
12941302
}
12951303

12961304
/**
@@ -1338,7 +1346,7 @@ class WebDriver {
13381346
* @param connection CDP Connection
13391347
*/
13401348
async register(username, password, connection) {
1341-
this._wsConnection.on('message', (message) => {
1349+
this._cdpWsConnection.on('message', (message) => {
13421350
const params = JSON.parse(message)
13431351

13441352
if (params.method === 'Fetch.authRequired') {
@@ -1383,7 +1391,7 @@ class WebDriver {
13831391
* @param callback callback called when we intercept requests.
13841392
*/
13851393
async onIntercept(connection, httpResponse, callback) {
1386-
this._wsConnection.on('message', (message) => {
1394+
this._cdpWsConnection.on('message', (message) => {
13871395
const params = JSON.parse(message)
13881396
if (params.method === 'Fetch.requestPaused') {
13891397
const requestPausedParams = params['params']
@@ -1420,7 +1428,7 @@ class WebDriver {
14201428
* @returns {Promise<void>}
14211429
*/
14221430
async onLogEvent(connection, callback) {
1423-
this._wsConnection.on('message', (message) => {
1431+
this._cdpWsConnection.on('message', (message) => {
14241432
const params = JSON.parse(message)
14251433
if (params.method === 'Runtime.consoleAPICalled') {
14261434
const consoleEventParams = params['params']
@@ -1457,7 +1465,7 @@ class WebDriver {
14571465
async onLogException(connection, callback) {
14581466
await connection.execute('Runtime.enable', {}, null)
14591467

1460-
this._wsConnection.on('message', (message) => {
1468+
this._cdpWsConnection.on('message', (message) => {
14611469
const params = JSON.parse(message)
14621470

14631471
if (params.method === 'Runtime.exceptionThrown') {
@@ -1510,7 +1518,7 @@ class WebDriver {
15101518
null,
15111519
)
15121520

1513-
this._wsConnection.on('message', async (message) => {
1521+
this._cdpWsConnection.on('message', async (message) => {
15141522
const params = JSON.parse(message)
15151523
if (params.method === 'Runtime.bindingCalled') {
15161524
let payload = JSON.parse(params['params']['payload'])

0 commit comments

Comments
 (0)