SeleniumHQ/selenium · error · Error
Params must be an instance of…
Error message
Params must be an instance of BrowsingContextPartitionDescriptor or StorageKeyPartitionDescriptor. Received:'${partition}' What it means
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.
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.
Example fix
// before
const result = await storage.getCookies(filter, contextId) // raw string
// after
const { BrowsingContextPartitionDescriptor } = require('selenium-webdriver/bidi/partitionDescriptor')
const result = await storage.getCookies(filter, new BrowsingContextPartitionDescriptor(contextId)) Defensive patterns
Strategy: type-guard
Validate before calling
function isPartitionDescriptor(v) {
return v === undefined ||
v instanceof BrowsingContextPartitionDescriptor ||
v instanceof StorageKeyPartitionDescriptor
}
if (!isPartitionDescriptor(partition)) {
throw new TypeError('partition must be a partition descriptor')
} Type guard
function isPartitionDescriptor(v) {
return v === undefined ||
v instanceof BrowsingContextPartitionDescriptor ||
v instanceof StorageKeyPartitionDescriptor
} Prevention
- 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.
When it happens
Trigger: Calling storage.getCookies(filter, 'ctx123') (raw string), getCookies(filter, {type:'context',context:'ctx123'}) (plain object), or getCookies(filter, someOtherDescriptorInstance).
Common situations: 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.
Related errors
- Params must be an instance of CookieFilter. Received
- Params must be an instance of PartialCookie. Received
- Value must be an instance of BytesValue. Received
- CookieHeader must be an instance of Header. Received
- browsingContexts should be string or string array
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/40a6a23406f2b9cc.
Report an issue: GitHub.
Appendix: source
Thrown at javascript/selenium-webdriver/bidi/storage.js:60
/**
* 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,
},
}
let response = await this.bidi.send(command)
let cookies = []
response.result.cookies.forEach((cookie) => {
cookies.push(
new Cookie(View on GitHub (pinned to aa36b38e69)