{"record":{"id":"cd848e4560acf88c","repo":"SeleniumHQ/selenium","slug":"cookieheader-must-be-an-instance-of-header-receiv","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/continueRequestParameters.js","lineNumber":57,"sourceCode":"    if (!(value instanceof BytesValue)) {\n      throw new Error(`Value must be an instance of BytesValue. Received: '${value})'`)\n    }\n    this.#map.set('body', Object.fromEntries(value.asMap()))\n    return this\n  }\n\n  /**\n   * Sets the cookies for the request.\n   *\n   * @param {Header[]} cookieHeaders - An array of cookie headers.\n   * @returns {ContinueRequestParameters} - The current instance of the ContinueRequestParameters for chaining.\n   * @throws {Error} - If a cookie header 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 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) => {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/continueRequestParameters.js#L39-L75","documentation":"Thrown by `ContinueRequestParameters.cookies()` when any element of the passed array is not a `Header` instance. The method iterates the array and calls `.asMap()` on each element, so plain `{name, value}` cookie objects are rejected even if their shape looks correct. The loop throws on the first bad element.","triggerScenarios":"Calling `params.cookies([{name:'session', value:'abc'}])` with plain objects; passing an array of mixed types; passing `Cookie` objects (the richer type from networkTypes) instead of `Header` objects.","commonSituations":"Confusing the cookies-as-headers representation required by continueRequest with the richer Cookie type; building the array from deserialized JSON; reusing plain cookie 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 array element is a Header instance, not a plain object or a Cookie"],"exampleFix":"// before\nparams.cookies([{ name: 'session', value: 'abc' }])\n// after\nconst { Header, BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nparams.cookies([\n  new Header('Cookie', new BytesValue(BytesValue.Type.STRING, 'session=abc'))\n])","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":["cookies() expects Header[] (name + BytesValue), not plain cookie objects","Validate the whole array before calling, since the loop throws on the first bad element"],"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"}