{"record":{"id":"bba69c5d6e6ffa7d","repo":"SeleniumHQ/selenium","slug":"header-value-must-be-an-instance-of-header-receiv","errorCode":null,"errorMessage":"Header value must be an instance of Header. Received:'${header}'","messagePattern":"Header value must be an instance of Header\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/continueRequestParameters.js","lineNumber":77,"sourceCode":"      cookies.push(Object.fromEntries(header.asMap()))\n    })\n\n    this.#map.set('cookies', cookies)\n    return this\n  }\n\n  /**\n   * Sets the headers for the request.\n   *\n   * @param {Header[]} headers - An array of Header objects.\n   * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.\n   * @throws {Error} - If the header value is not an instance of Header.\n   */\n  headers(headers) {\n    const headerList = []\n    headers.forEach((header) => {\n      if (!(header instanceof Header)) {\n        throw new Error(`Header value must be an instance of Header. Received:'${header}'`)\n      }\n      headerList.push(Object.fromEntries(header.asMap()))\n    })\n\n    this.#map.set('headers', headerList)\n    return this\n  }\n\n  /**\n   * Sets the HTTP method for the request.\n   *\n   * @param {string} method - The HTTP method to be set.\n   * @returns {ContinueRequestParameters} - The updated `continueRequestParameters` object.\n   * @throws {Error} - If the method parameter is not a string.\n   */\n  method(method) {\n    if (typeof method !== 'string') {\n      throw new Error(`Http method must be a string. Received: '${method})'`)","sourceCodeStart":59,"sourceCodeEnd":95,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/continueRequestParameters.js#L59-L95","documentation":"Thrown by `ContinueRequestParameters.headers()` when any element of the passed array is not a `Header` instance. Each element is serialized via `.asMap()`, so plain `{name, value}` objects are rejected. The loop throws on the first bad element.","triggerScenarios":"Calling `params.headers([{name:'Content-Type', value:'application/json'}])` with plain objects; passing an array of strings; reusing fetch/axios header maps directly.","commonSituations":"Developers pass header literals read from config files; reusing HTTP-client header objects which are plain maps rather than Header instances.","solutions":["Build each header as `new Header(name, new BytesValue(BytesValue.Type.STRING, value))`","Import `{ Header, BytesValue }` from `selenium-webdriver/bidi/networkTypes`","Ensure every element is a Header instance with a BytesValue value"],"exampleFix":"// before\nparams.headers([{ name: 'Accept', value: '*/*' }])\n// after\nconst { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nparams.headers([new Header('Accept', new BytesValue(BytesValue.Type.STRING, '*/*'))])","handlingStrategy":"type-guard","validationCode":"const { Header } = require('selenium-webdriver/bidi/networkTypes')\nif (arr.every(h => h instanceof Header)) params.headers(arr)","typeGuard":"const { Header } = require('selenium-webdriver/bidi/networkTypes')\nconst allHeaders = (arr) => Array.isArray(arr) && arr.every(h => h instanceof Header)","tryCatchPattern":null,"preventionTips":["Convert plain header maps to Header instances before calling headers()","Header values must be BytesValue, not raw strings"],"tags":["bidi","network-interception","validation","header","type-check"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}