@@ -124,6 +124,7 @@ const io = require('./io')
124
124
const remote = require ( './remote' )
125
125
const webdriver = require ( './lib/webdriver' )
126
126
const zip = require ( './io/zip' )
127
+ const cdp = require ( './devtools/CDPConnection' )
127
128
const { Browser, Capabilities } = require ( './lib/capabilities' )
128
129
const { Zip } = require ( './io/zip' )
129
130
@@ -666,6 +667,38 @@ class Driver extends webdriver.WebDriver {
666
667
)
667
668
)
668
669
}
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
+ }
669
702
}
670
703
671
704
/**
0 commit comments