{"record":{"id":"923dde4d56822a5e","repo":"SeleniumHQ/selenium","slug":"value-must-be-an-instance-of-bytesvalue-received-923dde","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/networkTypes.js","lineNumber":102,"sourceCode":"    return map\n  }\n}\n\n/**\n * Represents a header with a name and value.\n * Described in https://w3c.github.io/webdriver-bidi/#type-network-Header.\n */\nclass Header {\n  /**\n   * Creates a new Header instance.\n   * @param {string} name - The name of the header.\n   * @param {BytesValue} value - The value of the header.\n   * @throws {Error} If the value is not an instance of BytesValue.\n   */\n  constructor(name, value) {\n    this._name = name\n    if (!(value instanceof BytesValue)) {\n      throw new Error(`Value must be an instance of BytesValue. Received: '${value}'`)\n    }\n    this._value = value\n  }\n\n  /**\n   * Gets the name of the header.\n   * @returns {string} The name of the header.\n   */\n  get name() {\n    return this._name\n  }\n\n  /**\n   * Gets the value of the header.\n   * @returns {BytesValue} The value of the header.\n   */\n  get value() {\n    return this._value","sourceCodeStart":84,"sourceCodeEnd":120,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/networkTypes.js#L84-L120","documentation":"Thrown by the Header constructor (networkTypes.js) when its value argument is not an instance of BytesValue. Per the WebDriver BiDi spec a network Header value must be a BytesValue (type+value) object, so the constructor enforces the type before storing it. A raw string or number is rejected because Header.asMap() later calls value.asMap().","triggerScenarios":"Calling new Header('content-type', 'application/json') (raw string), new Header('x', 123), or new Header('x', {type:'string', value:'v'}) (plain object that is structurally but not structurally an instance).","commonSituations":"Assuming Header takes a plain string value (as in classic HTTP libraries); deserializing JSON into a plain object and passing it; forgetting to wrap the value in BytesValue.","solutions":["Wrap the value in a BytesValue instance before constructing the Header: new Header('content-type', new BytesValue(BytesValue.Type.STRING, 'application/json')).","For binary data, use new BytesValue(BytesValue.Type.BASE64, base64String).","If you receive header data as plain objects, map each to new Header(h.name, new BytesValue(h.value.type, h.value.value))."],"exampleFix":"// before\nconst header = new Header('content-type', 'application/json')\n\n// after\nconst { BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nconst header = new Header('content-type', new BytesValue(BytesValue.Type.STRING, 'application/json'))","handlingStrategy":"type-guard","validationCode":"function toHeaderValue(v) {\n  if (v instanceof BytesValue) return v\n  if (typeof v === 'string') return new BytesValue(BytesValue.Type.STRING, v)\n  throw new TypeError('Header value must be BytesValue or string')\n}","typeGuard":"function isBytesValue(v) {\n  return v instanceof BytesValue\n}","tryCatchPattern":null,"preventionTips":["Always wrap header values in new BytesValue(BytesValue.Type.STRING, text) or .BASE64 for binary.","Write a small helper that converts plain strings to BytesValue for convenience.","Use TypeScript/JSDoc so the editor flags raw strings."],"tags":["bidi","network","header","bytesvalue","type-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}