SeleniumHQ/selenium · error · Error
Header must be an instance of Header. Received:'${header}'
Error message
Header must be an instance of Header. Received:'${header}' What it means
Thrown by ProvideResponseParameters.headers() when any element of the headers array is not an instance of the Header class. The method serializes each via header.asMap(), so each entry must be a Header instance. Plain objects, strings, or [name, value] tuples are rejected.
Source
Thrown at javascript/selenium-webdriver/bidi/provideResponseParameters.js:78
cookies.push(Object.fromEntries(header.asMap()))
})
this.#map.set('cookies', cookies)
return this
}
/**
* Sets the headers for the response.
*
* @param {Header[]} headers - The headers to be set.
* @returns {ProvideResponseParameters} - Returns the ProvideResponseParameters object for chaining.
* @throws {Error} - If the provided header is not an instance of Header.
*/
headers(headers) {
const headerList = []
headers.forEach((header) => {
if (!(header instanceof Header)) {
throw new Error(`Header 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 to set.
* @returns {ProvideResponseParameters} - Returns the ProvideResponseParameters object 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
- Convert each header to a Header instance: params.headers([new Header('content-type', new BytesValue(BytesValue.Type.STRING, 'application/json'))]).
- If you hold a plain object map, spread it into Header instances: Object.entries(map).map(([k,v]) => new Header(k, new BytesValue(BytesValue.Type.STRING, v))).
- Ensure no raw strings or tuples are present in the array.
Example fix
// before
const params = new ProvideResponseParameters(id).headers({ 'content-type': 'application/json' })
// after
const { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')
const params = new ProvideResponseParameters(id).headers([
new Header('content-type', new BytesValue(BytesValue.Type.STRING, 'application/json')),
]) Defensive patterns
Strategy: type-guard
Validate before calling
const allHeaders = headers.every((h) => h instanceof Header)
if (!allHeaders) throw new TypeError('every header must be a Header instance') Type guard
function isHeaderArray(v) {
return Array.isArray(v) && v.every((h) => h instanceof Header)
} Prevention
- Convert plain object header maps to Header[] via Object.entries mapping.
- Never pass [name, value] tuples or raw strings.
- Reuse a buildHeader(name, value) helper to enforce the BytesValue wrapping.
When it happens
Trigger: Calling params.headers([{name:'content-type', value:'application/json'}]) (plain objects), params.headers([['content-type','application/json']]) (tuples), or params.headers(['content-type: application/json']) (raw strings).
Common situations: Passing a plain object map of headers (common in fetch/axios); reusing entries from a Headers/Web Headers object without converting; deserializing header JSON.
Related errors
- CookieHeader must be an instance of Header. Received:'${head
- Params must be an instance of ProvideResponseParameters. Rec
- Value must be an instance of BytesValue. Received: '${value}
- Value must be an instance of BytesValue. Received: ${typeof
- Params must be an instance of AddInterceptParameters. Receiv
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/fd92a8f68ee1cba1.
Report an issue: GitHub.