delete_cookies
Remove specific browser cookies by name to manage session data, clear tracking information, or reset authentication states during automated browser testing.
Instructions
Delete cookies by name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| names | Yes | Cookie names to delete | |
| tabId | No | Tab ID to operate on (uses active tab if not specified) |
Implementation Reference
- src/tools/cookies.ts:96-138 (handler)The async handler function for the 'delete_cookies' tool. It retrieves cookies from the page, filters those matching the provided names, and deletes them by setting an empty value with an expired timestamp using page.setCookie.async ({ names, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; try { // Get all cookies first const allCookies = await page.cookies(); // Find cookies to delete const cookiesToDelete = allCookies.filter((cookie) => names.includes(cookie.name) ); // Delete each matching cookie const browserResult = await getBrowser(); if (browserResult.success) { const context = browserResult.data.defaultBrowserContext(); for (const cookie of cookiesToDelete) { await context.clearPermissionOverrides(); // Delete by setting empty value and expired date await page.setCookie({ name: cookie.name, value: '', domain: cookie.domain, path: cookie.path, expires: 0, }); } } return handleResult(ok({ deleted: cookiesToDelete.length, names: cookiesToDelete.map((c) => c.name), })); } catch (error) { return handleResult(err(normalizeError(error))); } }
- src/schemas.ts:191-194 (schema)Zod schema defining the input for delete_cookies: an array of cookie names (required) and optional tabId.export const deleteCookiesSchema = z.object({ names: z.array(z.string()).min(1).describe('Cookie names to delete'), tabId: tabIdSchema, });
- src/tools/cookies.ts:92-139 (registration)Registration of the 'delete_cookies' tool via server.tool(), including name, description, input schema reference, and inline handler function.server.tool( 'delete_cookies', 'Delete cookies by name', deleteCookiesSchema.shape, async ({ names, tabId }) => { const pageResult = await getPageForOperation(tabId); if (!pageResult.success) { return handleResult(pageResult); } const page = pageResult.data; try { // Get all cookies first const allCookies = await page.cookies(); // Find cookies to delete const cookiesToDelete = allCookies.filter((cookie) => names.includes(cookie.name) ); // Delete each matching cookie const browserResult = await getBrowser(); if (browserResult.success) { const context = browserResult.data.defaultBrowserContext(); for (const cookie of cookiesToDelete) { await context.clearPermissionOverrides(); // Delete by setting empty value and expired date await page.setCookie({ name: cookie.name, value: '', domain: cookie.domain, path: cookie.path, expires: 0, }); } } return handleResult(ok({ deleted: cookiesToDelete.length, names: cookiesToDelete.map((c) => c.name), })); } catch (error) { return handleResult(err(normalizeError(error))); } } );