{"record":{"id":"11b978be154f3e65","repo":"SeleniumHQ/selenium","slug":"header-value-must-be-an-instance-of-header-receiv-11b978","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/continueResponseParameters.js","lineNumber":84,"sourceCode":"    }\n\n    this.#map.set('credentials', { type: 'password', username: username, password: password })\n\n    return this\n  }\n\n  /**\n   * Sets the headers for the response.\n   *\n   * @param {Header[]} headers - An array of Header objects representing the headers.\n   * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters 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 reason phrase for the response.\n   *\n   * @param {string} reasonPhrase - The reason phrase for the response.\n   * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.\n   * @throws {Error} - If the reason phrase is not a string.\n   */\n  reasonPhrase(reasonPhrase) {\n    if (typeof reasonPhrase !== 'string') {\n      throw new Error(`Reason phrase must be a string. Received: '${reasonPhrase})'`)","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/continueResponseParameters.js#L66-L102","documentation":"Thrown by `ContinueResponseParameters.headers()` when any element of the passed array is not a `Header` instance. Same logic as the request-side headers(): each element is serialized via `.asMap()` and the loop throws on the first bad element.","triggerScenarios":"Calling `params.headers([{name:'Cache-Control', value:'no-cache'}])` with plain objects; passing an array of strings; reusing response header objects from other HTTP libraries.","commonSituations":"Plain header maps read from config; reusing HTTP-client response 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: 'Cache-Control', value: 'no-cache' }])\n// after\nconst { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nparams.headers([new Header('Cache-Control', new BytesValue(BytesValue.Type.STRING, 'no-cache'))])","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":["Response headers are Header[] with BytesValue values","Convert plain maps to Header instances before calling"],"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"}