@@ -167,7 +167,8 @@ const { createValueEngine, createDisabledEngine } = require('./extras/Playwright
167167 * Playwright: {
168168 * url: "http://localhost",
169169 * chromium: {
170- * browserWSEndpoint: 'ws://localhost:9222/devtools/browser/c5aa6160-b5bc-4d53-bb49-6ecb36cd2e0a'
170+ * browserWSEndpoint: 'ws://localhost:9222/devtools/browser/c5aa6160-b5bc-4d53-bb49-6ecb36cd2e0a',
171+ * cdpConnection: false // default is false
171172 * }
172173 * }
173174 * }
@@ -272,6 +273,7 @@ class Playwright extends Helper {
272273 this . sessionPages = { } ;
273274 this . activeSessionName = '' ;
274275 this . isElectron = false ;
276+ this . isCDPConnection = false ;
275277 this . electronSessions = [ ] ;
276278 this . storageState = null ;
277279
@@ -347,6 +349,7 @@ class Playwright extends Helper {
347349 this . isRemoteBrowser = ! ! this . playwrightOptions . browserWSEndpoint ;
348350 this . isElectron = this . options . browser === 'electron' ;
349351 this . userDataDir = this . playwrightOptions . userDataDir ;
352+ this . isCDPConnection = this . playwrightOptions . cdpConnection ;
350353 popupStore . defaultAction = this . options . defaultPopupAction ;
351354 }
352355
@@ -692,6 +695,15 @@ class Playwright extends Helper {
692695 async _startBrowser ( ) {
693696 if ( this . isElectron ) {
694697 this . browser = await playwright . _electron . launch ( this . playwrightOptions ) ;
698+ } else if ( this . isRemoteBrowser && this . isCDPConnection ) {
699+ try {
700+ this . browser = await playwright [ this . options . browser ] . connectOverCDP ( this . playwrightOptions ) ;
701+ } catch ( err ) {
702+ if ( err . toString ( ) . indexOf ( 'ECONNREFUSED' ) ) {
703+ throw new RemoteBrowserConnectionRefused ( err ) ;
704+ }
705+ throw err ;
706+ }
695707 } else if ( this . isRemoteBrowser ) {
696708 try {
697709 this . browser = await playwright [ this . options . browser ] . connect ( this . playwrightOptions ) ;
0 commit comments