You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: clearCookies({ name: "" }) unintentionally clears all cookies instead of only nameless cookies #43112
import{test,expect}from'@playwright/test';test('clearCookies({ name: "" }) should only clear unnamed cookies',async({ context })=>{// A nameless cookie (RFC 6265 §4.1.1, e.g. from Set-Cookie: =nameless; Path=/)// and a regular named cookieawaitcontext.addCookies([{name: '',value: 'nameless',domain: 'example.com',path: '/'},{name: 'session',value: 'secret',domain: 'example.com',path: '/'},]);// Attempt to delete only the nameless cookieawaitcontext.clearCookies({name: ''});constcookies=awaitcontext.cookies();expect(cookies.map(c=>c.name)).toEqual(['session']);});
Run with npx playwright test.
(The exact same issue also reproduces with APIRequestContext.clearCookies({ name: '' })).
Expected behavior
Only the cookie with name: "" is deleted. The named cookie ('session') remains in the context.
Actual behavior
All cookies in the context are deleted (cookies is []):
Because matches uses if (!value) return true;, passing empty string "" (name: "") is treated as falsy and returns true for all cookies regardless of cookie.name.
Since hasClearCookiesFilter({ name: '' }) is true (options.name !== undefined), Playwright enters the filtering path instead of doClearCookies(), but because cookieMatchesClearFilter returns true for every cookie, all cookies are expired and deleted.
The check should be if (value === undefined) return true; (the same applies to domain and path).
Environment
Not environment-specific: reproduces across Chromium, Firefox, and WebKit on Windows, macOS, and Linux.
No browser launch needed when reproduced via APIRequestContext or unit test.
Hi, I'm the Playwright bot and I took a first look.
Reproduced on 1.64.0-next at a18dade00769, but the result is browser-specific and #43114 is only a partial fix.APIRequestContext.clearCookies({ name: '' }) matches the report exactly and removes both cookies. The same BrowserContext repro does not preserve the named cookie on any engine, but fails differently:
Firefox: removes session and leaves the nameless cookie.
WebKit: removes both cookies.
Applying #43114's value === undefined change makes the API-request and WebKit cases pass. Chromium still throws the protocol error, while Firefox leaves both cookies in place. The predicate change is correct, but it does not fully fix BrowserContext.clearCookies({ name: '' }).
An equivalent APIRequestContext regression test before and after that change: it fails with [] before and passes after.
npm 1.63.0 with Chromium 153.0.8010.12: the browser-context repro throws the same Invalid cookie fields error. The API-request cookie methods used by the report are not available on APIRequestContext in npm 1.63.0.
Activity
alok-108 commentedon Oct 4, 2026
Thanks for addressing #43112 so quickly, Lazizbek Ergashev (@lazerg)! Looks great to me.
github-actions commentedon Oct 5, 2026
Hi, I'm the Playwright bot and I took a first look.
Reproduced on
1.64.0-nextata18dade00769, but the result is browser-specific and #43114 is only a partial fix.APIRequestContext.clearCookies({ name: '' })matches the report exactly and removes both cookies. The sameBrowserContextrepro does not preserve the named cookie on any engine, but fails differently:Protocol error (Storage.setCookies): Invalid cookie fields.sessionand leaves the nameless cookie.Applying #43114's
value === undefinedchange makes the API-request and WebKit cases pass. Chromium still throws the protocol error, while Firefox leaves both cookies in place. The predicate change is correct, but it does not fully fixBrowserContext.clearCookies({ name: '' }).Minimal repro
What I ran
1.64.0-next, commita18dade00769, headless Linux: Chromium 156.0.8078.4, Firefox 157.0, and WebKit 26.6.7e6158dcd595).APIRequestContextregression test before and after that change: it fails with[]before and passes after.1.63.0with Chromium 153.0.8010.12: the browser-context repro throws the sameInvalid cookie fieldserror. The API-request cookie methods used by the report are not available onAPIRequestContextin npm1.63.0.Triaged on Linux by the Playwright bot - agent run