{"record":{"id":"1a6f055f6a37798b","repo":"SeleniumHQ/selenium","slug":"params-must-be-an-instance-of-partialcookie-recei","errorCode":null,"errorMessage":"Params must be an instance of PartialCookie. Received:'${cookie}'","messagePattern":"Params must be an instance of PartialCookie\\. Received:'(.+?)'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/storage.js","lineNumber":118,"sourceCode":"        )\n        return { cookies, partitionKey }\n      }\n\n      return { cookies }\n    }\n  }\n\n  /**\n   * Sets a cookie using the provided cookie object and partition.\n   *\n   * @param {PartialCookie} cookie - The cookie object to set.\n   * @param {(BrowsingContextPartitionDescriptor|StorageKeyPartitionDescriptor)} [partition] - The partition to use for the cookie.\n   * @returns {PartitionKey} The partition key of the set cookie.\n   * @throws {Error} If the cookie parameter is not an instance of PartialCookie or if the partition parameter is not an instance of PartitionDescriptor.\n   */\n  async setCookie(cookie, partition = undefined) {\n    if (!(cookie instanceof PartialCookie)) {\n      throw new Error(`Params must be an instance of PartialCookie. Received:'${cookie}'`)\n    }\n\n    if (\n      partition !== undefined &&\n      !(partition instanceof BrowsingContextPartitionDescriptor || partition instanceof StorageKeyPartitionDescriptor)\n    ) {\n      throw new Error(\n        `Params must be an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor. Received:'${partition}'`,\n      )\n    }\n\n    const command = {\n      method: 'storage.setCookie',\n      params: {\n        cookie: cookie ? Object.fromEntries(cookie.asMap()) : undefined,\n        partition: partition ? Object.fromEntries(partition.asMap()) : undefined,\n      },\n    }","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/storage.js#L100-L136","documentation":"Thrown by Storage.setCookie() when the cookie argument is not an instance of PartialCookie. The method serializes the cookie via Object.fromEntries(cookie.asMap()) to build the storage.setCookie BiDi command, so it requires the PartialCookie class. A plain object, a classic Cookie, or a string is rejected by the instanceof guard.","triggerScenarios":"Calling storage.setCookie({name:'a',value:'b',domain:'example.com'}) (plain object), setCookie(classicCookieInstance), or setCookie('a=b').","commonSituations":"Migrating from the classic driver.manage().addCookie({...}) API which takes a plain object; passing a networkTypes Cookie instead of a PartialCookie; deserializing cookie JSON.","solutions":["Build a PartialCookie with a BytesValue value: setCookie(new PartialCookie('name', new BytesValue(BytesValue.Type.STRING, 'val'), 'example.com').path('/')).","Convert any classic/plain cookie object into a PartialCookie instance before passing.","Ensure the cookie value is wrapped in BytesValue (PartialCookie itself enforces this in its constructor)."],"exampleFix":"// before\nawait storage.setCookie({ name: 'session', value: 'abc', domain: 'example.com' })\n\n// after\nconst { PartialCookie } = require('selenium-webdriver/bidi/partialCookie')\nconst { BytesValue } = require('selenium-webdriver/bidi/networkTypes')\nawait storage.setCookie(\n  new PartialCookie('session', new BytesValue(BytesValue.Type.STRING, 'abc'), 'example.com')\n)","handlingStrategy":"type-guard","validationCode":"if (!(cookie instanceof PartialCookie)) {\n  throw new TypeError('cookie must be a PartialCookie instance')\n}","typeGuard":"function isPartialCookie(v) {\n  return v instanceof PartialCookie\n}","tryCatchPattern":null,"preventionTips":["Build cookies with PartialCookie + BytesValue value; do not pass classic plain-object cookies.","Convert classic cookie objects via a helper into PartialCookie instances.","Ensure the cookie value is wrapped in BytesValue."],"tags":["bidi","storage","cookie","type-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}