{"record":{"id":"0c5e7702e21a418e","repo":"SeleniumHQ/selenium","slug":"params-must-be-an-instance-of-cookiefilter-receiv","errorCode":null,"errorMessage":"Params must be an instance of CookieFilter. Received:'${filter}'","messagePattern":"Params must be an instance of CookieFilter\\. Received:'(.+?)'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/storage.js","lineNumber":53,"sourceCode":"    if (!(await this._driver.getCapabilities()).get('webSocketUrl')) {\n      throw Error('WebDriver instance must support BiDi protocol')\n    }\n\n    this.bidi = await this._driver.getBidi()\n  }\n\n  /**\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    }","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/storage.js#L35-L71","documentation":"Thrown by Storage.getCookies() when an optional filter argument is provided but is not an instance of CookieFilter. The method serializes the filter via Object.fromEntries(filter.asMap()) to build the storage.getCookies BiDi command, so it requires the CookieFilter class. A plain object, string, or other type is rejected by the instanceof guard.","triggerScenarios":"Calling storage.getCookies({name:'session'}) (plain object), getCookies('session') (string), or passing a PartialCookie/Cookie instance by mistake.","commonSituations":"Assuming getCookies accepts a plain object filter (as classic WebDriver does); passing a Cookie object when a CookieFilter is needed; deserializing filter JSON into a plain object.","solutions":["Build a CookieFilter instance: getCookies(new CookieFilter().name('session').value(new BytesValue(...))).","If you do not need a filter, omit the argument entirely (getCookies() returns all cookies).","Convert any plain-object filter into a CookieFilter instance before passing."],"exampleFix":"// before\nconst result = await storage.getCookies({ name: 'session' })\n\n// after\nconst { CookieFilter } = require('selenium-webdriver/bidi/cookieFilter')\nconst result = await storage.getCookies(new CookieFilter().name('session'))","handlingStrategy":"type-guard","validationCode":"if (filter !== undefined && !(filter instanceof CookieFilter)) {\n  throw new TypeError('filter must be a CookieFilter instance')\n}","typeGuard":"function isCookieFilter(v) {\n  return v === undefined || v instanceof CookieFilter\n}","tryCatchPattern":null,"preventionTips":["Build filters with the CookieFilter builder; omit the arg to fetch all cookies.","Do not pass plain objects from classic cookie APIs.","Convert parsed filter JSON into a CookieFilter before calling."],"tags":["bidi","storage","cookie","filter","type-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}