SeleniumHQ/selenium · error · Error

Reason phrase must be a string. Received: '${reasonPhrase})'

Error message

Reason phrase must be a string. Received: '${reasonPhrase})'

What it means

Thrown by `ContinueResponseParameters.reasonPhrase()` when the argument is not a string (`typeof reasonPhrase !== 'string'`). The value is stored directly into the command map. The error string carries a cosmetic typo: an extra `)` (`'${reasonPhrase})'`).

Source

Thrown at javascript/selenium-webdriver/bidi/continueResponseParameters.js:102

        throw new Error(`Header value must be an instance of Header. Received:'${header}'`)
      }
      headerList.push(Object.fromEntries(header.asMap()))
    })

    this.#map.set('headers', headerList)
    return this
  }

  /**
   * Sets the reason phrase for the response.
   *
   * @param {string} reasonPhrase - The reason phrase for the response.
   * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
   * @throws {Error} - If the reason phrase is not a string.
   */
  reasonPhrase(reasonPhrase) {
    if (typeof reasonPhrase !== 'string') {
      throw new Error(`Reason phrase must be a string. Received: '${reasonPhrase})'`)
    }
    this.#map.set('reasonPhrase', reasonPhrase)
    return this
  }

  /**
   * Sets the status code for the response.
   *
   * @param {number} statusCode - The status code to set.
   * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
   * @throws {Error} - If the `statusCode` parameter is not an integer.
   */
  statusCode(statusCode) {
    if (!Number.isInteger(statusCode)) {
      throw new Error(`Status must be an integer. Received:'${statusCode}'`)
    }

    this.#map.set('statusCode', statusCode)

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Pass a plain string like 'OK', 'Not Found'
  2. If you only need the status code, omit the reasonPhrase() call entirely — it is optional

Example fix

// before
params.reasonPhrase()
// after
params.reasonPhrase('OK')
Defensive patterns

Strategy: validation

Validate before calling

if (typeof reason === 'string') params.reasonPhrase(reason)

Type guard

const isReasonString = (r) => typeof r === 'string'

Prevention

When it happens

Trigger: Calling `params.reasonPhrase(undefined)`, `params.reasonPhrase(200)`, or passing an object.

Common situations: Reason phrase omitted (undefined) when only the status code was intended; numeric status confused with the reason phrase.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/265df4f5371ac210. Report an issue: GitHub.