SeleniumHQ/selenium · error · Error
CookieHeader must be an instance of Header. Received:'${head
Error message
CookieHeader must be an instance of Header. Received:'${header}' What it means
Thrown by `ContinueResponseParameters.cookies()` when any element of the passed array is not a `Header` instance. Identical logic to the request-side cookies(): each element is serialized via `.asMap()`, so plain objects are rejected and the loop throws on the first bad element.
Source
Thrown at javascript/selenium-webdriver/bidi/continueResponseParameters.js:42
class ContinueResponseParameters {
#map = new Map()
constructor(request) {
this.#map.set('request', request)
}
/**
* Sets the cookies for the response.
*
* @param {Header[]} cookieHeaders - The array of cookie headers.
* @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.
* @throws {Error} - If the cookieHeader is not an instance of Header.
*/
cookies(cookieHeaders) {
const cookies = []
cookieHeaders.forEach((header) => {
if (!(header instanceof Header)) {
throw new Error(`CookieHeader must be an instance of Header. Received:'${header}'`)
}
cookies.push(Object.fromEntries(header.asMap()))
})
this.#map.set('cookies', cookies)
return this
}
/**
* Sets the credentials for authentication.
*
* @param {string} username - The username for authentication.
* @param {string} password - The password for authentication.
* @returns {ContinueResponseParameters} The current instance of the ContinueResponseParameters for chaining.
* @throws {Error} If username or password is not a string.
*/
credentials(username, password) {
if (typeof username !== 'string') {View on GitHub (pinned to aa36b38e69)
Solutions
- Build each entry as `new Header(name, new BytesValue(BytesValue.Type.STRING, value))`
- Import `{ Header, BytesValue }` from `selenium-webdriver/bidi/networkTypes`
- Ensure every element is a Header instance
Example fix
// before
params.cookies([{ name: 'Set-Cookie', value: 'sid=1; Path=/' }])
// after
const { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')
params.cookies([new Header('Set-Cookie', new BytesValue(BytesValue.Type.STRING, 'sid=1; Path=/'))]) Defensive patterns
Strategy: type-guard
Validate before calling
const { Header } = require('selenium-webdriver/bidi/networkTypes')
if (arr.every(h => h instanceof Header)) params.cookies(arr) Type guard
const { Header } = require('selenium-webdriver/bidi/networkTypes')
const allHeaders = (arr) => Array.isArray(arr) && arr.every(h => h instanceof Header) Prevention
- Response cookies are Header[], same shape as the request side
- Validate each element before calling
When it happens
Trigger: Calling `params.cookies([{name:'Set-Cookie', value:'...'}])` with plain objects; passing `Cookie` instances instead of `Header` instances.
Common situations: Reusing the same plain-object array shape from request interception on the response side; building Set-Cookie headers as literals from config.
Related errors
- CookieHeader must be an instance of Header. Received:'${head
- Header value must be an instance of Header. Received:'${head
- Header value must be an instance of Header. Received:'${head
- Value must be an instance of BytesValue. Received: '${value}
- Value must be an instance of BytesValue. Received:'${value}'
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/625889a046333700.
Report an issue: GitHub.