{"record":{"id":"1cf21a142a3e7d76","repo":"SeleniumHQ/selenium","slug":"value-must-be-an-instance-of-bytesvalue-received-1cf21a","errorCode":null,"errorMessage":"Value must be an instance of BytesValue. Received:'${value}'","messagePattern":"Value must be an instance of BytesValue\\. Received:'(.+?)'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/partialCookie.js","lineNumber":38,"sourceCode":"/**\n * Represents a partial cookie used to set cookies.\n * Described in https://w3c.github.io/webdriver-bidi/#command-storage-setCookie.\n * @class\n */\nclass PartialCookie {\n  #map = new Map()\n\n  /**\n   * Represents a partial cookie.\n   * @class\n   * @param {string} name - The name of the cookie.\n   * @param {BytesValue} value - The value of the cookie as an instance of BytesValue.\n   * @param {string} domain - The domain of the cookie.\n   */\n  constructor(name, value, domain) {\n    this.#map.set('name', name)\n    if (!(value instanceof BytesValue)) {\n      throw new Error(`Value must be an instance of BytesValue. Received:'${value}'`)\n    }\n    this.#map.set('value', Object.fromEntries(value.asMap()))\n    this.#map.set('domain', domain)\n  }\n\n  /**\n   * Sets the path for the cookie.\n   *\n   * @param {string} path - The path for the cookie.\n   * @returns {PartialCookie} - The updated PartialCookie instance for chaining.\n   */\n  path(path) {\n    this.#map.set('path', path)\n    return this\n  }\n\n  /**\n   * Sets the size of the cookie.","sourceCodeStart":20,"sourceCodeEnd":56,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/partialCookie.js#L20-L56","documentation":"Thrown by the PartialCookie constructor (partialCookie.js) when the value argument is not an instance of BytesValue. The WebDriver BiDi cookie value must be a BytesValue (type+value), and the constructor serializes it via Object.fromEntries(value.asMap()), so the instance type is enforced. A raw string or object fails the instanceof guard.","triggerScenarios":"Calling new PartialCookie('name', 'val', 'example.com') (raw string value), new PartialCookie('name', 123, 'example.com'), or new PartialCookie('name', {type:'string',value:'val'}, 'example.com').","commonSituations":"Coming from the classic cookies API where values are plain strings; building a cookie from parsed JSON; forgetting that the BiDi cookie value is a BytesValue, not a string.","solutions":["Wrap the cookie value in a BytesValue: new PartialCookie('name', new BytesValue(BytesValue.Type.STRING, 'val'), 'example.com').","For binary cookie values, use BytesValue.Type.BASE64 with a base64 string.","If migrating from a classic cookie object, convert cookie.value into new BytesValue(cookie.value.type || BytesValue.Type.STRING, cookie.value.value || cookie.value)."],"exampleFix":"// before\nconst cookie = new PartialCookie('session', 'abc123', 'example.com')\n\n// after\nconst { BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nconst cookie = new PartialCookie('session', new BytesValue(BytesValue.Type.STRING, 'abc123'), 'example.com')","handlingStrategy":"type-guard","validationCode":"function toCookieValue(v) {\n  if (v instanceof BytesValue) return v\n  if (typeof v === 'string') return new BytesValue(BytesValue.Type.STRING, v)\n  throw new TypeError('cookie value must be BytesValue or string')\n}","typeGuard":"function isBytesValue(v) {\n  return v instanceof BytesValue\n}","tryCatchPattern":null,"preventionTips":["Remember BiDi cookie values are BytesValue, unlike classic string cookie values.","Keep a helper that converts a classic cookie into a PartialCookie with a BytesValue.","Use BytesValue.Type.BASE64 for binary cookie values."],"tags":["bidi","storage","cookie","bytesvalue","type-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}