{"record":{"id":"625889a046333700","repo":"SeleniumHQ/selenium","slug":"cookieheader-must-be-an-instance-of-header-receiv-625889","errorCode":null,"errorMessage":"CookieHeader must be an instance of Header. Received:'${header}'","messagePattern":"CookieHeader must be an instance of Header\\. Received:'(.+?)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/continueResponseParameters.js","lineNumber":42,"sourceCode":"class ContinueResponseParameters {\n  #map = new Map()\n\n  constructor(request) {\n    this.#map.set('request', request)\n  }\n\n  /**\n   * Sets the cookies for the response.\n   *\n   * @param {Header[]} cookieHeaders - The array of cookie headers.\n   * @returns {ContinueResponseParameters} - The current instance of the ContinueResponseParameters for chaining.\n   * @throws {Error} - If the cookieHeader is not an instance of Header.\n   */\n  cookies(cookieHeaders) {\n    const cookies = []\n    cookieHeaders.forEach((header) => {\n      if (!(header instanceof Header)) {\n        throw new Error(`CookieHeader must be an instance of Header. Received:'${header}'`)\n      }\n      cookies.push(Object.fromEntries(header.asMap()))\n    })\n\n    this.#map.set('cookies', cookies)\n    return this\n  }\n\n  /**\n   * Sets the credentials for authentication.\n   *\n   * @param {string} username - The username for authentication.\n   * @param {string} password - The password for authentication.\n   * @returns {ContinueResponseParameters} The current instance of the ContinueResponseParameters for chaining.\n   * @throws {Error} If username or password is not a string.\n   */\n  credentials(username, password) {\n    if (typeof username !== 'string') {","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/continueResponseParameters.js#L24-L60","documentation":"Thrown by `ContinueResponseParameters.cookies()` when any element of the passed array is not a `Header` instance. Identical logic to the request-side cookies(): each element is serialized via `.asMap()`, so plain objects are rejected and the loop throws on the first bad element.","triggerScenarios":"Calling `params.cookies([{name:'Set-Cookie', value:'...'}])` with plain objects; passing `Cookie` instances instead of `Header` instances.","commonSituations":"Reusing the same plain-object array shape from request interception on the response side; building Set-Cookie headers as literals from config.","solutions":["Build each entry 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"],"exampleFix":"// before\nparams.cookies([{ name: 'Set-Cookie', value: 'sid=1; Path=/' }])\n// after\nconst { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nparams.cookies([new Header('Set-Cookie', new BytesValue(BytesValue.Type.STRING, 'sid=1; Path=/'))])","handlingStrategy":"type-guard","validationCode":"const { Header } = require('selenium-webdriver/bidi/networkTypes')\nif (arr.every(h => h instanceof Header)) params.cookies(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 cookies are Header[], same shape as the request side","Validate each element before calling"],"tags":["bidi","network-interception","validation","header","cookie","type-check"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}