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 `ContinueRequestParameters.body()` when the argument is not a `BytesValue` instance (from `networkTypes.js`). The method calls `value.asMap()` to serialize the body into the BiDi continue-request command, so it needs a real `BytesValue` carrying a type ('string' or 'base64') and a value — a raw string or plain object is rejected. The error string carries a cosmetic typo: an extra `)` appears before the closing quote (`'${value})'`).

Source

Thrown at javascript/selenium-webdriver/bidi/continueRequestParameters.js:40

 * Described in https://w3c.github.io/webdriver-bidi/#command-network-continueRequest.
 */
class ContinueRequestParameters {
  #map = new Map()

  constructor(request) {
    this.#map.set('request', request)
  }

  /**
   * Sets the body value for the request.
   *
   * @param {BytesValue} value - The value to set as the body. Must be an instance of BytesValue.
   * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.
   * @throws {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: '${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}'`)
      }

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Wrap the body in `new BytesValue(BytesValue.Type.STRING, text)` for text or `new BytesValue(BytesValue.Type.BASE64, base64Str)` for binary
  2. Import `{ BytesValue }` from `selenium-webdriver/bidi/networkTypes`
  3. For binary data, base64-encode first, then use Type.BASE64

Example fix

// before
params.body('hello world')
// after
const { BytesValue } = require('selenium-webdriver/bidi/networkTypes')
params.body(new BytesValue(BytesValue.Type.STRING, 'hello world'))
Defensive patterns

Strategy: type-guard

Validate before calling

const { BytesValue } = require('selenium-webdriver/bidi/networkTypes')
if (body instanceof BytesValue) params.body(body)

Type guard

const { BytesValue } = require('selenium-webdriver/bidi/networkTypes')
const isBytesValue = (v) => v instanceof BytesValue

Prevention

When it happens

Trigger: Calling `params.body('hello')` with a raw string; passing `{type:'string', value:'hello'}`; passing a Buffer instead of wrapping it in `new BytesValue(BytesValue.Type.BASE64, base64String)`.

Common situations: Developers pass the request body as a plain string assuming the builder will wrap it; JSON-deserialized body payloads; forgetting that binary data must be base64-encoded and wrapped in a BytesValue.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/7252d75b10bcda97. Report an issue: GitHub.