diff --git a/lib/chromedriver.js b/lib/chromedriver.js index bd0cd626..a7c852a7 100644 --- a/lib/chromedriver.js +++ b/lib/chromedriver.js @@ -97,6 +97,8 @@ export class Chromedriver extends events.EventEmitter { // Store the running driver version /** @type {string|null} */ this._driverVersion = null; + /** @type {Record | null} */ + this._onlineStatus = null; } get log() { @@ -525,6 +527,16 @@ 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) { @@ -630,6 +642,7 @@ export class Chromedriver extends events.EventEmitter { this.proc.once('exit', (code, signal) => { this._driverVersion = null; this._desiredProtocol = null; + this._onlineStatus = null; processIsAlive = false; if ( this.state !== Chromedriver.STATE_STOPPED && @@ -710,6 +723,7 @@ export class Chromedriver extends events.EventEmitter { if (!_.isPlainObject(status) || !status.ready) { throw new Error(`The response to the /status API is not valid: ${JSON.stringify(status)}`); } + this._onlineStatus = status; const versionMatch = VERSION_PATTERN.exec(status.build?.version ?? ''); if (versionMatch) { this._driverVersion = versionMatch[1];