Skip to content

Commit 51b582b

Browse files
HmihalyHoffer Mihály
andauthored
Playwright: connect over cdp option (#3309)
* cdp connection option * update docs with cdp connection option * update docs in helper file * fix annotation Co-authored-by: Hoffer Mihály <[email protected]>
1 parent 35c6c95 commit 51b582b

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

docs/helpers/Playwright.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ Traces will be saved to `output/trace`
131131
Playwright: {
132132
url: "http://localhost",
133133
chromium: {
134-
browserWSEndpoint: 'ws://localhost:9222/devtools/browser/c5aa6160-b5bc-4d53-bb49-6ecb36cd2e0a'
134+
browserWSEndpoint: 'ws://localhost:9222/devtools/browser/c5aa6160-b5bc-4d53-bb49-6ecb36cd2e0a',
135+
cdpConnection: false // default is false
135136
}
136137
}
137138
}

lib/helper/Playwright.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)