SeleniumHQ/selenium · error · Error
Value must be an instance of BytesValue. Received: ${typeof
Error message
Value must be an instance of BytesValue. Received: ${typeof value} with value: ${value} What it means
Thrown by ProvideResponseParameters.body() when the value argument is not an instance of BytesValue. The setter serializes the body via Object.fromEntries(value.asMap()), so it requires the BytesValue class. A raw string, buffer, or plain object is rejected because the BiDi response body must be a typed BytesValue.
Source
Thrown at javascript/selenium-webdriver/bidi/provideResponseParameters.js:41
* @class
*/
class ProvideResponseParameters {
#map = new Map()
constructor(request) {
this.#map.set('request', request)
}
/**
* Sets the body value for the response parameters.
*
* @param {BytesValue} value - The value to set as the body. Must be an instance of BytesValue.
* @returns {ProvideResponseParameters} - Returns the ProvideResponseParameters object for chaining.
* @throws {Error} - Throws an error if the value is not an instance of BytesValue.
*/
body(value) {
if (!(value instanceof BytesValue)) {
throw new Error(`Value must be an instance of BytesValue. Received: ${typeof value} with value: ${value}`)
}
this.#map.set('body', Object.fromEntries(value.asMap()))
return this
}
/**
* Sets the cookie headers for the response.
*
* @param {Header[]} cookieHeaders - An array of cookie headers.
* @returns {ProvideResponseParameters} - Returns the ProvideResponseParameters object for chaining.
* @throws {Error} - Throws an 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}'`)
}View on GitHub (pinned to aa36b38e69)
Solutions
- Wrap the body in a BytesValue: params.body(new BytesValue(BytesValue.Type.STRING, 'response body text')).
- For binary bodies, encode as base64 and use new BytesValue(BytesValue.Type.BASE64, base64String).
- If body is optional, simply omit the body() call instead of passing an empty/invalid value.
Example fix
// before
const params = new ProvideResponseParameters(id).body('Hello World')
// after
const { BytesValue } = require('selenium-webdriver/bidi/networkTypes')
const params = new ProvideResponseParameters(id)
.body(new BytesValue(BytesValue.Type.STRING, 'Hello World')) Defensive patterns
Strategy: type-guard
Validate before calling
function toBody(v) {
if (v instanceof BytesValue) return v
if (typeof v === 'string') return new BytesValue(BytesValue.Type.STRING, v)
throw new TypeError('body must be BytesValue or string')
} Type guard
function isBytesValue(v) {
return v instanceof BytesValue
} Prevention
- Wrap response bodies in BytesValue (STRING for text, BASE64 for binary).
- Do not pass Node Buffers directly; encode to base64 first.
- Omit body() when the response has no body.
When it happens
Trigger: Calling params.body('response body text') (raw string), params.body(Buffer.from(...)), or params.body({type:'string', value:'v'}).
Common situations: Assuming body() accepts a plain string like fetch/Express APIs; passing a Node Buffer instead of a base64 BytesValue; deserializing a stored response object.
Related errors
- Params must be an instance of ProvideResponseParameters. Rec
- Value must be an instance of BytesValue. Received: '${value}
- 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
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/eb2ebbe963ee3191.
Report an issue: GitHub.