SeleniumHQ/selenium · error · Error

Header value must be an instance of Header. Received:'${head

Error message

Header value must be an instance of Header. Received:'${header}'

What it means

Thrown by `ContinueResponseParameters.headers()` when any element of the passed array is not a `Header` instance. Same logic as the request-side headers(): each element is serialized via `.asMap()` and the loop throws on the first bad element.

Source

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

    }

    this.#map.set('credentials', { type: 'password', username: username, password: password })

    return this
  }

  /**
   * Sets the headers for the response.
   *
   * @param {Header[]} headers - An array of Header objects representing the headers.
   * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
   * @throws {Error} - If the header value is not an instance of Header.
   */
  headers(headers) {
    const headerList = []
    headers.forEach((header) => {
      if (!(header instanceof Header)) {
        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})'`)

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Build each header as `new Header(name, new BytesValue(BytesValue.Type.STRING, value))`
  2. Import `{ Header, BytesValue }` from `selenium-webdriver/bidi/networkTypes`
  3. Ensure every element is a Header instance with a BytesValue value

Example fix

// before
params.headers([{ name: 'Cache-Control', value: 'no-cache' }])
// after
const { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')
params.headers([new Header('Cache-Control', new BytesValue(BytesValue.Type.STRING, 'no-cache'))])
Defensive patterns

Strategy: type-guard

Validate before calling

const { Header } = require('selenium-webdriver/bidi/networkTypes')
if (arr.every(h => h instanceof Header)) params.headers(arr)

Type guard

const { Header } = require('selenium-webdriver/bidi/networkTypes')
const allHeaders = (arr) => Array.isArray(arr) && arr.every(h => h instanceof Header)

Prevention

When it happens

Trigger: Calling `params.headers([{name:'Cache-Control', value:'no-cache'}])` with plain objects; passing an array of strings; reusing response header objects from other HTTP libraries.

Common situations: Plain header maps read from config; reusing HTTP-client response header objects which are plain maps rather than Header instances.

Related errors


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