Skip to content

Commit

Permalink
feat: add webdriver bidi support
Browse files Browse the repository at this point in the history
  • Loading branch information
jlipps committed Jan 3, 2024
1 parent 3ea79da commit f379b6c
Show file tree
Hide file tree
Showing 4 changed files with 4,023 additions and 13,994 deletions.
27 changes: 21 additions & 6 deletions lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const CD_CONSTRAINTS = /** @type {const} */ ({
logPath: { isString: true },
autodownloadEnabled: { isBoolean: true },
disableBuildCheck: { isBoolean: true },
browserName: { isString: true }
browserName: { isString: true },
});

const STANDARD_CAPS_LOWER = new Set([...STANDARD_CAPS].map((cap) => cap.toLowerCase()));
Expand All @@ -38,6 +38,11 @@ export class ChromiumDriver extends BaseDriver {
proxyReqRes;
proxyCommand;

doesSupportBidi = true;

/** @type {string|null} */
_bidiProxyUrl = null;

proxyActive() {
return this._proxyActive;
}
Expand All @@ -46,6 +51,11 @@ export class ChromiumDriver extends BaseDriver {
return true;
}

get bidiProxyUrl() {
return this._bidiProxyUrl;
}


/**
*
* @param {W3CChromiumDriverCaps} jsonwpDesiredCapabilities
Expand All @@ -59,14 +69,17 @@ export class ChromiumDriver extends BaseDriver {
jsonwpRequiredCaps,
w3cCapabilities,
) {
const [sessionId, caps] = /** @type {[string, ChromiumDriverCaps]} */(await super.createSession(jsonwpDesiredCapabilities, jsonwpRequiredCaps, w3cCapabilities));
await this.startChromedriverSession();
return [sessionId, caps];
const [sessionId,] = /** @type {[string, ChromiumDriverCaps]} */(await super.createSession(jsonwpDesiredCapabilities, jsonwpRequiredCaps, w3cCapabilities));
const returnedCaps = await this.startChromedriverSession();
if (returnedCaps.webSocketUrl) {
this._bidiProxyUrl = (/** @type {string|null} */(/** @type {unknown} */(returnedCaps.webSocketUrl)));
}
return [sessionId, returnedCaps];
}

getSessionCaps() {
return Object.keys(this.opts).reduce((acc, capName) => {
if (STANDARD_CAPS_LOWER.has(capName) || capName.startsWith(CHROME_VENDOR_PREFIX) || capName.startsWith(EDGE_VENDOR_PREFIX)) {
if (STANDARD_CAPS_LOWER.has(capName.toLowerCase()) || capName.startsWith(CHROME_VENDOR_PREFIX) || capName.startsWith(EDGE_VENDOR_PREFIX)) {
acc[capName] = this.opts[capName];
}
return acc;
Expand All @@ -88,10 +101,11 @@ export class ChromiumDriver extends BaseDriver {
};

this.cd = new Chromedriver(cdOpts);
await this.cd.start(this.getSessionCaps());
const cdStartRes = /** @type {ChromiumDriverCaps} */(await this.cd.start(this.getSessionCaps()));
this._proxyActive = true;
this.proxyReqRes = this.cd.proxyReq.bind(this.cd);
this.proxyCommand = this.cd.sendCommand.bind(this.cd);
return cdStartRes;
}

/**
Expand All @@ -104,6 +118,7 @@ export class ChromiumDriver extends BaseDriver {
// @ts-ignore
await super.deleteSession(sessionId, driverData);
this._proxyActive = false;
this._bidiProxyUrl = null;
this.proxyReqRes = null;
this.proxyCommand = null;
if (this.cd) {
Expand Down
Loading

0 comments on commit f379b6c

Please sign in to comment.