SeleniumHQ/selenium · error · Error

Params must be an instance of CookieFilter. Received:'${filt

Error message

Params must be an instance of CookieFilter. Received:'${filter}'

What it means

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.

Source

Thrown at javascript/selenium-webdriver/bidi/storage.js:53

    if (!(await this._driver.getCapabilities()).get('webSocketUrl')) {
      throw Error('WebDriver instance must support BiDi protocol')
    }

    this.bidi = await this._driver.getBidi()
  }

  /**
   * Retrieves cookies based on the provided filter and partition.
   *
   * @param {CookieFilter} [filter] - The filter to apply to the cookies.
   * @param {(BrowsingContextPartitionDescriptor|StorageKeyPartitionDescriptor)} [partition] - The partition to retrieve cookies from.
   * @returns {Promise<{ cookies: Cookie[], partitionKey: (PartitionKey|undefined) }>} - A promise that resolves to an object containing the retrieved cookies and an optional partition key.
   * @throws {Error} If the filter parameter is provided but is not an instance of CookieFilter.
   * @throws {Error} If the partition parameter is provided but is not an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor.
   */
  async getCookies(filter = undefined, partition = undefined) {
    if (filter !== undefined && !(filter instanceof CookieFilter)) {
      throw new Error(`Params must be an instance of CookieFilter. Received:'${filter}'`)
    }

    if (
      partition !== undefined &&
      !(partition instanceof BrowsingContextPartitionDescriptor || partition instanceof StorageKeyPartitionDescriptor)
    ) {
      throw new Error(
        `Params must be an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor. Received:'${partition}'`,
      )
    }

    const command = {
      method: 'storage.getCookies',
      params: {
        filter: filter ? Object.fromEntries(filter.asMap()) : undefined,
        partition: partition ? Object.fromEntries(partition.asMap()) : undefined,
      },
    }

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Build a CookieFilter instance: getCookies(new CookieFilter().name('session').value(new BytesValue(...))).
  2. If you do not need a filter, omit the argument entirely (getCookies() returns all cookies).
  3. Convert any plain-object filter into a CookieFilter instance before passing.

Example fix

// before
const result = await storage.getCookies({ name: 'session' })

// after
const { CookieFilter } = require('selenium-webdriver/bidi/cookieFilter')
const result = await storage.getCookies(new CookieFilter().name('session'))
Defensive patterns

Strategy: type-guard

Validate before calling

if (filter !== undefined && !(filter instanceof CookieFilter)) {
  throw new TypeError('filter must be a CookieFilter instance')
}

Type guard

function isCookieFilter(v) {
  return v === undefined || v instanceof CookieFilter
}

Prevention

When it happens

Trigger: Calling storage.getCookies({name:'session'}) (plain object), getCookies('session') (string), or passing a PartialCookie/Cookie instance by mistake.

Common situations: 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.

Related errors


AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14). Data as JSON: /api/errors/0c5e7702e21a418e. Report an issue: GitHub.