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 `ContinueRequestParameters.cookies()` when any element of the passed array is not a `Header` instance. The method iterates the array and calls `.asMap()` on each element, so plain `{name, value}` cookie objects are rejected even if their shape looks correct. The loop throws on the first bad element.
Source
Thrown at javascript/selenium-webdriver/bidi/continueRequestParameters.js:57
if (!(value instanceof BytesValue)) {
throw new Error(`Value must be an instance of BytesValue. Received: '${value})'`)
}
this.#map.set('body', Object.fromEntries(value.asMap()))
return this
}
/**
* Sets the cookies for the request.
*
* @param {Header[]} cookieHeaders - An array of cookie headers.
* @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.
* @throws {Error} - If a cookie header 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 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) => {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 array element is a Header instance, not a plain object or a Cookie
Example fix
// before
params.cookies([{ name: 'session', value: 'abc' }])
// after
const { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')
params.cookies([
new Header('Cookie', new BytesValue(BytesValue.Type.STRING, 'session=abc'))
]) 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
- cookies() expects Header[] (name + BytesValue), not plain cookie objects
- Validate the whole array before calling, since the loop throws on the first bad element
When it happens
Trigger: Calling `params.cookies([{name:'session', value:'abc'}])` with plain objects; passing an array of mixed types; passing `Cookie` objects (the richer type from networkTypes) instead of `Header` objects.
Common situations: Confusing the cookies-as-headers representation required by continueRequest with the richer Cookie type; building the array from deserialized JSON; reusing plain cookie 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/cd848e4560acf88c.
Report an issue: GitHub.