{"record":{"id":"eb2ebbe963ee3191","repo":"SeleniumHQ/selenium","slug":"value-must-be-an-instance-of-bytesvalue-received-eb2ebb","errorCode":null,"errorMessage":"Value must be an instance of BytesValue. Received: ${typeof value} with value: ${value}","messagePattern":"Value must be an instance of BytesValue\\. Received: (.+?) with value: (.+?)","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/provideResponseParameters.js","lineNumber":41,"sourceCode":" * @class\n */\nclass ProvideResponseParameters {\n  #map = new Map()\n\n  constructor(request) {\n    this.#map.set('request', request)\n  }\n\n  /**\n   * Sets the body value for the response parameters.\n   *\n   * @param {BytesValue} value - The value to set as the body. Must be an instance of BytesValue.\n   * @returns {ProvideResponseParameters} - Returns the ProvideResponseParameters object for chaining.\n   * @throws {Error} - Throws an 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: ${typeof value} with value: ${value}`)\n    }\n    this.#map.set('body', Object.fromEntries(value.asMap()))\n    return this\n  }\n\n  /**\n   * Sets the cookie headers for the response.\n   *\n   * @param {Header[]} cookieHeaders - An array of cookie headers.\n   * @returns {ProvideResponseParameters} - Returns the ProvideResponseParameters object for chaining.\n   * @throws {Error} - Throws an 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":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/provideResponseParameters.js#L23-L59","documentation":"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.","triggerScenarios":"Calling params.body('response body text') (raw string), params.body(Buffer.from(...)), or params.body({type:'string', value:'v'}).","commonSituations":"Assuming body() accepts a plain string like fetch/Express APIs; passing a Node Buffer instead of a base64 BytesValue; deserializing a stored response object.","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."],"exampleFix":"// before\nconst params = new ProvideResponseParameters(id).body('Hello World')\n\n// after\nconst { BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nconst params = new ProvideResponseParameters(id)\n  .body(new BytesValue(BytesValue.Type.STRING, 'Hello World'))","handlingStrategy":"type-guard","validationCode":"function toBody(v) {\n  if (v instanceof BytesValue) return v\n  if (typeof v === 'string') return new BytesValue(BytesValue.Type.STRING, v)\n  throw new TypeError('body must be BytesValue or string')\n}","typeGuard":"function isBytesValue(v) {\n  return v instanceof BytesValue\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["bidi","network","provide-response","bytesvalue","type-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}