Skip to main content
Glama

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
NameRequiredDescriptionDefault
namesYesCookie names to delete
tabIdNoTab ID to operate on (uses active tab if not specified)

Implementation Reference

  • 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))); } }
  • 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, });
  • 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))); } } );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/andytango/puppeteer-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server