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 `ContinueRequestParameters.headers()` when any element of the passed array is not a `Header` instance. Each element is serialized via `.asMap()`, so plain `{name, value}` objects are rejected. The loop throws on the first bad element.

Source

Thrown at javascript/selenium-webdriver/bidi/continueRequestParameters.js:77

      cookies.push(Object.fromEntries(header.asMap()))
    })

    this.#map.set('cookies', cookies)
    return this
  }

  /**
   * Sets the headers for the request.
   *
   * @param {Header[]} headers - An array of Header objects.
   * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters 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 HTTP method for the request.
   *
   * @param {string} method - The HTTP method to be set.
   * @returns {ContinueRequestParameters} - The updated `continueRequestParameters` object.
   * @throws {Error} - If the method parameter is not a string.
   */
  method(method) {
    if (typeof method !== 'string') {
      throw new Error(`Http method must be a string. Received: '${method})'`)

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: 'Accept', value: '*/*' }])
// after
const { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')
params.headers([new Header('Accept', new BytesValue(BytesValue.Type.STRING, '*/*'))])
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:'Content-Type', value:'application/json'}])` with plain objects; passing an array of strings; reusing fetch/axios header maps directly.

Common situations: Developers pass header literals read from config files; reusing HTTP-client 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/bba69c5d6e6ffa7d. Report an issue: GitHub.