SeleniumHQ/selenium · error · Error

Params must be an instance of PartialCookie. Received:'${coo

Error message

Params must be an instance of PartialCookie. Received:'${cookie}'

What it means

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.

Source

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

        )
        return { cookies, partitionKey }
      }

      return { cookies }
    }
  }

  /**
   * Sets a cookie using the provided cookie object and partition.
   *
   * @param {PartialCookie} cookie - The cookie object to set.
   * @param {(BrowsingContextPartitionDescriptor|StorageKeyPartitionDescriptor)} [partition] - The partition to use for the cookie.
   * @returns {PartitionKey} The partition key of the set cookie.
   * @throws {Error} If the cookie parameter is not an instance of PartialCookie or if the partition parameter is not an instance of PartitionDescriptor.
   */
  async setCookie(cookie, partition = undefined) {
    if (!(cookie instanceof PartialCookie)) {
      throw new Error(`Params must be an instance of PartialCookie. Received:'${cookie}'`)
    }

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

View on GitHub (pinned to aa36b38e69)

Solutions

  1. Build a PartialCookie with a BytesValue value: setCookie(new PartialCookie('name', new BytesValue(BytesValue.Type.STRING, 'val'), 'example.com').path('/')).
  2. Convert any classic/plain cookie object into a PartialCookie instance before passing.
  3. Ensure the cookie value is wrapped in BytesValue (PartialCookie itself enforces this in its constructor).

Example fix

// before
await storage.setCookie({ name: 'session', value: 'abc', domain: 'example.com' })

// after
const { PartialCookie } = require('selenium-webdriver/bidi/partialCookie')
const { BytesValue } = require('selenium-webdriver/bidi/networkTypes')
await storage.setCookie(
  new PartialCookie('session', new BytesValue(BytesValue.Type.STRING, 'abc'), 'example.com')
)
Defensive patterns

Strategy: type-guard

Validate before calling

if (!(cookie instanceof PartialCookie)) {
  throw new TypeError('cookie must be a PartialCookie instance')
}

Type guard

function isPartialCookie(v) {
  return v instanceof PartialCookie
}

Prevention

When it happens

Trigger: Calling storage.setCookie({name:'a',value:'b',domain:'example.com'}) (plain object), setCookie(classicCookieInstance), or setCookie('a=b').

Common situations: Migrating from the classic driver.manage().addCookie({...}) API which takes a plain object; passing a networkTypes Cookie instead of a PartialCookie; deserializing cookie JSON.

Related errors


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