reset_browser_data
Clear browser cookies, cache, localStorage, and sessionStorage to reset browser state for testing consent management platforms.
Instructions
Reset browser data including cookies, cache, localStorage, and sessionStorage
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| clearCookies | No | Clear browser cookies (default: true) | |
| clearCache | No | Clear browser cache (default: true) | |
| clearLocalStorage | No | Clear localStorage (default: true) | |
| clearSessionStorage | No | Clear sessionStorage (default: true) |
Implementation Reference
- src/tools/browser-reset.ts:13-45 (handler)The core handler function that implements the reset_browser_data tool logic, clearing cookies, cache, localStorage, and sessionStorage using Puppeteer's CDP session and page.evaluate.export async function resetBrowserData( page: Page, options: BrowserResetOptions = { clearCookies: true, clearCache: true, clearLocalStorage: true, clearSessionStorage: true, }, ): Promise<void> { const client = await page.target().createCDPSession(); // Clear cookies if (options.clearCookies) { await client.send("Network.clearBrowserCookies"); } // Clear browser cache if (options.clearCache) { await client.send("Network.clearBrowserCache"); } // Clear localStorage and sessionStorage if (options.clearLocalStorage || options.clearSessionStorage) { await page.evaluate((opts) => { if (opts.clearLocalStorage && typeof localStorage !== "undefined") { localStorage.clear(); } if (opts.clearSessionStorage && typeof sessionStorage !== "undefined") { sessionStorage.clear(); } }, options); } }
- src/tools/browser-reset.ts:3-8 (schema)Type definition for the options parameter used in resetBrowserData, matching the tool's inputSchema.export type BrowserResetOptions = { clearCookies?: boolean; clearCache?: boolean; clearLocalStorage?: boolean; clearSessionStorage?: boolean; };
- src/index.ts:143-169 (registration)Registration of the reset_browser_data tool in the TOOLS array, including name, description, and inputSchema.{ name: "reset_browser_data", description: "Reset browser data including cookies, cache, localStorage, and sessionStorage", inputSchema: { type: "object", properties: { clearCookies: { type: "boolean", description: "Clear browser cookies (default: true)", }, clearCache: { type: "boolean", description: "Clear browser cache (default: true)", }, clearLocalStorage: { type: "boolean", description: "Clear localStorage (default: true)", }, clearSessionStorage: { type: "boolean", description: "Clear sessionStorage (default: true)", }, }, required: [], }, },
- src/index.ts:474-510 (handler)Wrapper handler in the main tool dispatch switch (handleToolCall) that processes arguments and calls the resetBrowserData function.case "reset_browser_data": try { const options = { clearCookies: args.clearCookies ?? true, clearCache: args.clearCache ?? true, clearLocalStorage: args.clearLocalStorage ?? true, clearSessionStorage: args.clearSessionStorage ?? true, }; await resetBrowserData(page, options); const clearedItems = []; if (options.clearCookies) clearedItems.push("cookies"); if (options.clearCache) clearedItems.push("cache"); if (options.clearLocalStorage) clearedItems.push("localStorage"); if (options.clearSessionStorage) clearedItems.push("sessionStorage"); return { content: [ { type: "text", text: `Successfully cleared: ${clearedItems.join(", ")}`, }, ], isError: false, }; } catch (error) { return { content: [ { type: "text", text: `Failed to reset browser data: ${(error as Error).message}`, }, ], isError: true, }; }