Playwright API request contexts gain cookie management
Introduced 2026-10-07 · score 0.98
HOW TO USE IT
When API-level tests need request-context cookie control, use `addCookies()` to add cookies, `cookies()` to inspect them, and `clearCookies()` to remove them.
await request.addCookies([{ name: 'session-id', value: '42', url: 'https://example.com' }]);
console.log(await request.cookies('https://example.com'));
await request.clearCookies({ name: 'session-id' });WHY THIS HELPS
Manage cookies for an API request context during API-level testing.
REQUIREMENTS AND LIMITATIONS
- Version: v1.64.0
- addCookies(cookies) — `cookies` (required): Array of cookie objects. Each needs `name` and `value`, plus either `url` or both `domain` and `path`.
- cookies(urls) — `urls`: URL or list of URLs; filters returned cookies to those affecting the specified URLs. Omit to return all cookies.
- clearCookies(options) — `options.name`: String or RegExp filter; only cookies with the given name are removed. The options object and its filters are optional.
- Prerequisite: The methods were added in Playwright v1.64. Use an `APIRequestContext`; `browserContext.request` and `page.request` share their BrowserContext cookie jar, while `apiRequest.newContext()` creates an isolated cookie store.
- The methods mirror the `BrowserContext` methods.
FIRST-PARTY EVIDENCE
- https://github.com/microsoft/playwright/releases/tag/v1.64.0
- https://playwright.dev/docs/api/class-apirequestcontext
Check the installed version and the source before using it. Entry JSON