{"record":{"id":"7252d75b10bcda97","repo":"SeleniumHQ/selenium","slug":"value-must-be-an-instance-of-bytesvalue-received","errorCode":null,"errorMessage":"Value must be an instance of BytesValue. Received: '${value})'","messagePattern":"Value must be an instance of BytesValue\\. Received: '(.+?)\\)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/continueRequestParameters.js","lineNumber":40,"sourceCode":" * Described in https://w3c.github.io/webdriver-bidi/#command-network-continueRequest.\n */\nclass ContinueRequestParameters {\n  #map = new Map()\n\n  constructor(request) {\n    this.#map.set('request', request)\n  }\n\n  /**\n   * Sets the body value for the request.\n   *\n   * @param {BytesValue} value - The value to set as the body. Must be an instance of BytesValue.\n   * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.\n   * @throws {Error} - If the value is not an instance of BytesValue.\n   */\n  body(value) {\n    if (!(value instanceof BytesValue)) {\n      throw new Error(`Value must be an instance of BytesValue. Received: '${value})'`)\n    }\n    this.#map.set('body', Object.fromEntries(value.asMap()))\n    return this\n  }\n\n  /**\n   * Sets the cookies for the request.\n   *\n   * @param {Header[]} cookieHeaders - An array of cookie headers.\n   * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.\n   * @throws {Error} - If a cookie header is not an instance of Header.\n   */\n  cookies(cookieHeaders) {\n    const cookies = []\n    cookieHeaders.forEach((header) => {\n      if (!(header instanceof Header)) {\n        throw new Error(`CookieHeader must be an instance of Header. Received:'${header}'`)\n      }","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/continueRequestParameters.js#L22-L58","documentation":"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})'`).","triggerScenarios":"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)`.","commonSituations":"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.","solutions":["Wrap the body in `new BytesValue(BytesValue.Type.STRING, text)` for text or `new BytesValue(BytesValue.Type.BASE64, base64Str)` for binary","Import `{ BytesValue }` from `selenium-webdriver/bidi/networkTypes`","For binary data, base64-encode first, then use Type.BASE64"],"exampleFix":"// before\nparams.body('hello world')\n// after\nconst { BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nparams.body(new BytesValue(BytesValue.Type.STRING, 'hello world'))","handlingStrategy":"type-guard","validationCode":"const { BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nif (body instanceof BytesValue) params.body(body)","typeGuard":"const { BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nconst isBytesValue = (v) => v instanceof BytesValue","tryCatchPattern":null,"preventionTips":["Never pass a raw string as a BiDi body — always wrap in BytesValue","Binary payloads must be base64-encoded with BytesValue.Type.BASE64"],"tags":["bidi","network-interception","validation","bytes-value","type-check","typo"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}