{"record":{"id":"fd92a8f68ee1cba1","repo":"SeleniumHQ/selenium","slug":"header-must-be-an-instance-of-header-received","errorCode":null,"errorMessage":"Header must be an instance of Header. Received:'${header}'","messagePattern":"Header must be an instance of Header\\. Received:'(.+?)'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/provideResponseParameters.js","lineNumber":78,"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 response.\n   *\n   * @param {Header[]} headers - The headers to be set.\n   * @returns {ProvideResponseParameters} - Returns the ProvideResponseParameters object for chaining.\n   * @throws {Error} - If the provided header 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 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 to set.\n   * @returns {ProvideResponseParameters} - Returns the ProvideResponseParameters object 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":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/provideResponseParameters.js#L60-L96","documentation":"Thrown by ProvideResponseParameters.headers() when any element of the headers array is not an instance of the Header class. The method serializes each via header.asMap(), so each entry must be a Header instance. Plain objects, strings, or [name, value] tuples are rejected.","triggerScenarios":"Calling params.headers([{name:'content-type', value:'application/json'}]) (plain objects), params.headers([['content-type','application/json']]) (tuples), or params.headers(['content-type: application/json']) (raw strings).","commonSituations":"Passing a plain object map of headers (common in fetch/axios); reusing entries from a Headers/Web Headers object without converting; deserializing header JSON.","solutions":["Convert each header to a Header instance: params.headers([new Header('content-type', new BytesValue(BytesValue.Type.STRING, 'application/json'))]).","If you hold a plain object map, spread it into Header instances: Object.entries(map).map(([k,v]) => new Header(k, new BytesValue(BytesValue.Type.STRING, v))).","Ensure no raw strings or tuples are present in the array."],"exampleFix":"// before\nconst params = new ProvideResponseParameters(id).headers({ 'content-type': 'application/json' })\n\n// after\nconst { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nconst params = new ProvideResponseParameters(id).headers([\n  new Header('content-type', new BytesValue(BytesValue.Type.STRING, 'application/json')),\n])","handlingStrategy":"type-guard","validationCode":"const allHeaders = headers.every((h) => h instanceof Header)\nif (!allHeaders) throw new TypeError('every header must be a Header instance')","typeGuard":"function isHeaderArray(v) {\n  return Array.isArray(v) && v.every((h) => h instanceof Header)\n}","tryCatchPattern":null,"preventionTips":["Convert plain object header maps to Header[] via Object.entries mapping.","Never pass [name, value] tuples or raw strings.","Reuse a buildHeader(name, value) helper to enforce the BytesValue wrapping."],"tags":["bidi","network","provide-response","header","type-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}