Skip to content

Commit 10b1603

Browse files
raju249AutomatedTester
authored andcommitted
[js] Add initial code for firefox cdp to create cdp connection
1 parent 18fd53a commit 10b1603

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

javascript/node/selenium-webdriver/firefox.js

+33
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ const io = require('./io')
124124
const remote = require('./remote')
125125
const webdriver = require('./lib/webdriver')
126126
const zip = require('./io/zip')
127+
const cdp = require('./devtools/CDPConnection')
127128
const { Browser, Capabilities } = require('./lib/capabilities')
128129
const { Zip } = require('./io/zip')
129130

@@ -666,6 +667,38 @@ class Driver extends webdriver.WebDriver {
666667
)
667668
)
668669
}
670+
671+
/**
672+
* Creates a new WebSocket connection.
673+
* @return {!Promise<resolved>} A new CDP instance.
674+
*/
675+
async createCDPConnection(target) {
676+
const caps = await this.getCapabilities()
677+
const seOptions = caps['map_'].get('se:options') || new Map()
678+
const vendorInfo =
679+
caps['map_'].get('moz:debuggerAddress') ||
680+
new Map()
681+
const debuggerUrl = seOptions['cdp'] || vendorInfo['debuggerAddress']
682+
this._wsUrl = await this.getWsUrl(debuggerUrl, target)
683+
684+
return new Promise((resolve, reject) => {
685+
try {
686+
this._wsConnection = new WebSocket(this._wsUrl)
687+
} catch (err) {
688+
reject(err)
689+
return
690+
}
691+
692+
this._wsConnection.on('open', () => {
693+
this._cdpConnection = new cdp.CdpConnection(this._wsConnection)
694+
resolve(this._cdpConnection)
695+
})
696+
697+
this._wsConnection.on('error', (error) => {
698+
reject(error)
699+
})
700+
})
701+
}
669702
}
670703

671704
/**

0 commit comments

Comments
 (0)