SeleniumHQ/selenium · error · Error
Value must be an instance of BytesValue. Received: '${value}
Error message
Value must be an instance of BytesValue. Received: '${value}' What it means
Thrown by the Header constructor (networkTypes.js) when its value argument is not an instance of BytesValue. Per the WebDriver BiDi spec a network Header value must be a BytesValue (type+value) object, so the constructor enforces the type before storing it. A raw string or number is rejected because Header.asMap() later calls value.asMap().
Source
Thrown at javascript/selenium-webdriver/bidi/networkTypes.js:102
return map
}
}
/**
* Represents a header with a name and value.
* Described in https://w3c.github.io/webdriver-bidi/#type-network-Header.
*/
class Header {
/**
* Creates a new Header instance.
* @param {string} name - The name of the header.
* @param {BytesValue} value - The value of the header.
* @throws {Error} If the value is not an instance of BytesValue.
*/
constructor(name, value) {
this._name = name
if (!(value instanceof BytesValue)) {
throw new Error(`Value must be an instance of BytesValue. Received: '${value}'`)
}
this._value = value
}
/**
* Gets the name of the header.
* @returns {string} The name of the header.
*/
get name() {
return this._name
}
/**
* Gets the value of the header.
* @returns {BytesValue} The value of the header.
*/
get value() {
return this._valueView on GitHub (pinned to aa36b38e69)
Solutions
- Wrap the value in a BytesValue instance before constructing the Header: new Header('content-type', new BytesValue(BytesValue.Type.STRING, 'application/json')).
- For binary data, use new BytesValue(BytesValue.Type.BASE64, base64String).
- If you receive header data as plain objects, map each to new Header(h.name, new BytesValue(h.value.type, h.value.value)).
Example fix
// before
const header = new Header('content-type', 'application/json')
// after
const { BytesValue } = require('selenium-webdriver/bidi/networkTypes')
const header = new Header('content-type', new BytesValue(BytesValue.Type.STRING, 'application/json')) Defensive patterns
Strategy: type-guard
Validate before calling
function toHeaderValue(v) {
if (v instanceof BytesValue) return v
if (typeof v === 'string') return new BytesValue(BytesValue.Type.STRING, v)
throw new TypeError('Header value must be BytesValue or string')
} Type guard
function isBytesValue(v) {
return v instanceof BytesValue
} Prevention
- Always wrap header values in new BytesValue(BytesValue.Type.STRING, text) or .BASE64 for binary.
- Write a small helper that converts plain strings to BytesValue for convenience.
- Use TypeScript/JSDoc so the editor flags raw strings.
When it happens
Trigger: Calling new Header('content-type', 'application/json') (raw string), new Header('x', 123), or new Header('x', {type:'string', value:'v'}) (plain object that is structurally but not structurally an instance).
Common situations: Assuming Header takes a plain string value (as in classic HTTP libraries); deserializing JSON into a plain object and passing it; forgetting to wrap the value in BytesValue.
Related errors
- Value must be an instance of BytesValue. Received: ${typeof
- CookieHeader must be an instance of Header. Received:'${head
- Header must be an instance of Header. Received:'${header}'
- Params must be an instance of AddInterceptParameters. Receiv
- Params must be an instance of ContinueRequestParameters. Rec
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/923dde4d56822a5e.
Report an issue: GitHub.