{"record":{"id":"40a6a23406f2b9cc","repo":"SeleniumHQ/selenium","slug":"params-must-be-an-instance-of-browsingcontextparti","errorCode":null,"errorMessage":"Params must be an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor. Received:'${partition}'","messagePattern":"Params must be an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor\\. Received:'(.+?)'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/storage.js","lineNumber":60,"sourceCode":"  /**\n   * Retrieves cookies based on the provided filter and partition.\n   *\n   * @param {CookieFilter} [filter] - The filter to apply to the cookies.\n   * @param {(BrowsingContextPartitionDescriptor|StorageKeyPartitionDescriptor)} [partition] - The partition to retrieve cookies from.\n   * @returns {Promise<{ cookies: Cookie[], partitionKey: (PartitionKey|undefined) }>} - A promise that resolves to an object containing the retrieved cookies and an optional partition key.\n   * @throws {Error} If the filter parameter is provided but is not an instance of CookieFilter.\n   * @throws {Error} If the partition parameter is provided but is not an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor.\n   */\n  async getCookies(filter = undefined, partition = undefined) {\n    if (filter !== undefined && !(filter instanceof CookieFilter)) {\n      throw new Error(`Params must be an instance of CookieFilter. Received:'${filter}'`)\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.getCookies',\n      params: {\n        filter: filter ? Object.fromEntries(filter.asMap()) : undefined,\n        partition: partition ? Object.fromEntries(partition.asMap()) : undefined,\n      },\n    }\n\n    let response = await this.bidi.send(command)\n\n    let cookies = []\n    response.result.cookies.forEach((cookie) => {\n      cookies.push(\n        new Cookie(","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/storage.js#L42-L78","documentation":"Thrown by Storage.getCookies() when an optional partition argument is provided but is neither a BrowsingContextPartitionDescriptor nor a StorageKeyPartitionDescriptor. The method serializes the partition via asMap() for the storage.getCookies command, so it requires one of these two partition descriptor classes. Any other type (plain object, string) is rejected.","triggerScenarios":"Calling storage.getCookies(filter, 'ctx123') (raw string), getCookies(filter, {type:'context',context:'ctx123'}) (plain object), or getCookies(filter, someOtherDescriptorInstance).","commonSituations":"Passing the browsing context id string instead of a descriptor; building a partition from parsed JSON as a plain object; using the wrong partition descriptor class for the storage partition scheme.","solutions":["Wrap the context id in a BrowsingContextPartitionDescriptor: getCookies(filter, new BrowsingContextPartitionDescriptor(contextId)).","For source-origin partitioning, use new StorageKeyPartitionDescriptor().sourceOrigin(origin).","Omit the partition argument if you do not need partition-scoped cookies."],"exampleFix":"// before\nconst result = await storage.getCookies(filter, contextId) // raw string\n\n// after\nconst { BrowsingContextPartitionDescriptor } = require('selenium-webdriver/bidi/partitionDescriptor')\nconst result = await storage.getCookies(filter, new BrowsingContextPartitionDescriptor(contextId))","handlingStrategy":"type-guard","validationCode":"function isPartitionDescriptor(v) {\n  return v === undefined ||\n    v instanceof BrowsingContextPartitionDescriptor ||\n    v instanceof StorageKeyPartitionDescriptor\n}\nif (!isPartitionDescriptor(partition)) {\n  throw new TypeError('partition must be a partition descriptor')\n}","typeGuard":"function isPartitionDescriptor(v) {\n  return v === undefined ||\n    v instanceof BrowsingContextPartitionDescriptor ||\n    v instanceof StorageKeyPartitionDescriptor\n}","tryCatchPattern":null,"preventionTips":["Wrap context ids in BrowsingContextPartitionDescriptor; use StorageKeyPartitionDescriptor for source origins.","Do not pass raw context id strings.","Omit the partition arg when partition scoping is unneeded."],"tags":["bidi","storage","cookie","partition","type-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}