diff --git a/lib/chromedriver.js b/lib/chromedriver.js index e500c88..f11a6a7 100644 --- a/lib/chromedriver.js +++ b/lib/chromedriver.js @@ -527,16 +527,6 @@ export class Chromedriver extends events.EventEmitter { * @returns {keyof PROTOCOLS} */ syncProtocol() { - if (_.includes(this._onlineStatus?.message, 'OperaDriver')) { - this.log.info( - `OperaDriver is known to not support ${PROTOCOLS.W3C} protocol, ` + - `defaulting to ${PROTOCOLS.MJSONWP}. ` + - `See https://github.com/operasoftware/operachromiumdriver/issues/88` - ); - this._desiredProtocol = PROTOCOLS.MJSONWP; - return this._desiredProtocol; - } - if (this.driverVersion) { const coercedVersion = semver.coerce(this.driverVersion); if (!coercedVersion || coercedVersion.major < MIN_CD_VERSION_WITH_W3C_SUPPORT) { @@ -549,15 +539,23 @@ export class Chromedriver extends events.EventEmitter { } } - // Check only chromeOptions for now. - const chromeOptions = getCapValue(this.capabilities, 'chromeOptions', {}); - if (chromeOptions.w3c === false) { + const isOperaDriver = _.includes(this._onlineStatus?.message, 'OperaDriver'); + const chromeOptions = getCapValue(this.capabilities, 'chromeOptions'); + if (_.isPlainObject(chromeOptions) && chromeOptions.w3c === false) { this.log.info( `The ChromeDriver v. ${this.driverVersion} supports ${PROTOCOLS.W3C} protocol, ` + `but ${PROTOCOLS.MJSONWP} one has been explicitly requested`, ); this._desiredProtocol = PROTOCOLS.MJSONWP; return this._desiredProtocol; + } else if (isOperaDriver) { + // OperaDriver needs the W3C protocol to be requested explcitly, + // otherwise it defaults to JWP + if (_.isPlainObject(chromeOptions)) { + chromeOptions.w3c = true; + } else { + this.capabilities['goog:chromeOptions'].w3c = true; + } } this._desiredProtocol = PROTOCOLS.W3C; diff --git a/lib/protocol-helpers.js b/lib/protocol-helpers.js index 02352cf..22b6225 100644 --- a/lib/protocol-helpers.js +++ b/lib/protocol-helpers.js @@ -17,8 +17,8 @@ function toW3cCapName (capName) { * * @param {Record} allCaps * @param {string} rawCapName - * @param {any} defaultValue - * @returns + * @param {any} [defaultValue] + * @returns {any} */ function getCapValue (allCaps = {}, rawCapName, defaultValue) { for (const [capName, capValue] of _.toPairs(allCaps)) {