SeleniumHQ/selenium · error · Error

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

Error message

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

What it means

Thrown by Storage.deleteCookies() (BiDi storage module) when the cookieFilter argument is defined (not undefined) but is not an instance of the CookieFilter class. The WebDriver BiDi protocol requires typed descriptor objects; plain JS objects are rejected. Pass undefined to delete all cookies, or a properly constructed CookieFilter.

Source

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

        Object.prototype.hasOwnProperty.call(response.result.partitionKey, 'userContext') &&
        Object.prototype.hasOwnProperty.call(response.result.partitionKey, 'sourceOrigin')
      ) {
        return new PartitionKey(response.result.partitionKey.userContext, response.result.partitionKey.sourceOrigin)
      }
    }
  }

  /**
   * Deletes cookies based on the provided filter and partition.
   *
   * @param {CookieFilter} [cookieFilter] - The filter to apply to the cookies. Must be an instance of CookieFilter.
   * @param {(BrowsingContextPartitionDescriptor|StorageKeyPartitionDescriptor)} [partition] - The partition to delete cookies from. Must be an instance of either BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor.
   * @returns {PartitionKey} - The partition key of the deleted cookies, if available.
   * @throws {Error} - If the provided parameters are not of the correct type.
   */
  async deleteCookies(cookieFilter = undefined, partition = undefined) {
    if (cookieFilter !== undefined && !(cookieFilter instanceof CookieFilter)) {
      throw new Error(`Params must be an instance of CookieFilter. Received:'${cookieFilter}'`)
    }

    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.deleteCookies',
      params: {
        filter: cookieFilter ? Object.fromEntries(cookieFilter.asMap()) : undefined,
        partition: partition ? Object.fromEntries(partition.asMap()) : undefined,
      },
    }

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Construct the filter with new CookieFilter() and chain .name()/.domain()/.path()/.httpOnly()/.secure()/.sameSite()/.expiry().
  2. Pass undefined as the first argument to delete all cookies in the partition.
  3. Import CookieFilter from the bidi storage module: const { CookieFilter } = require('selenium-webdriver/bidi/storage').

Example fix

// before
storage.deleteCookies({ name: 'session' })
// after
const { CookieFilter } = require('selenium-webdriver/bidi/storage')
storage.deleteCookies(new CookieFilter().name('session'))
Defensive patterns

Strategy: type-guard

Validate before calling

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

Type guard

/**
 * @param {*} filter
 * @returns {filter is CookieFilter}
 */
function isCookieFilter(filter) {
  return filter instanceof CookieFilter
}

Prevention

When it happens

Trigger: Calling storage.deleteCookies({name:'session'}) with a plain object instead of a CookieFilter instance. Passing a string, number, or any non-CookieFilter value as the first argument. Migrating from the classic cookies API where plain objects were accepted.

Common situations: Migrating from classic WebDriver cookie APIs to BiDi; passing raw filter objects copied from examples that predate the typed BiDi API; forgetting to import and instantiate CookieFilter.

Related errors


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