Puppeteer: Unexpected string partition key
Cookie filtering received a string partition key where its filtering path expected a composite object.
Cookie filtering received a string partition key where its filtering path expected a composite object.
Error message
Unexpected string partition key
How this error happens
The shared cookie-filtering path expects a composite partition-key object when applying a partition filter. A browser path that returns a string key can violate that assumption.
The snippets use a BrowserContext named context containing a preference cookie with a string partition key.
await context.deleteMatchingCookies({
name: "preference",
partitionKey: "https://example.com",
});
How to fix
Read cookies, match the returned key shape explicitly, then delete the exact returned cookies through the public API.
const cookies = await context.cookies();
const matching = cookies.filter((cookie) => {
if (cookie.name !== "preference") {
return false;
}
const partitionKey = typeof cookie.partitionKey === "string"
? cookie.partitionKey
: cookie.partitionKey?.sourceOrigin;
return partitionKey === "https://example.com";
});
await context.deleteCookie(
...matching
);
Things to keep in mind
This keeps each selected cookie’s domain, path and partition key. The first call only fails when a matching cookie has the unexpected string-shaped key. Do not remove the partition filter and delete every same-named cookie.