browser_add_cookie_by_name
Add a cookie to the browser by specifying its name and value for web automation and testing scenarios.
Instructions
Add a cookie to the browser
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the cookie to add | |
| value | Yes | Value of the cookie to add |
Implementation Reference
- src/tools/cookieTools.ts:39-46 (handler)The handler function for the browser_add_cookie_by_name tool, which instantiates CookieService and calls addCookieByNameasync ({ name, value }) => { const driver = stateManager.getDriver(); const cookieService = new CookieService(driver); await cookieService.addCookieByName(name, value); return { content: [{ type: 'text', text: `Added cookie: ${name}` }], }; }
- src/tools/cookieTools.ts:35-38 (schema)Input schema using Zod for the tool parameters: name and value{ name: z.string().describe('Name of the cookie to add'), value: z.string().min(1).max(4096).describe('Value of the cookie to add'), },
- src/tools/cookieTools.ts:32-47 (registration)Registration of the browser_add_cookie_by_name tool using server.tool, including description, schema, and handlerserver.tool( 'browser_add_cookie_by_name', 'Add a cookie to the browser', { name: z.string().describe('Name of the cookie to add'), value: z.string().min(1).max(4096).describe('Value of the cookie to add'), }, async ({ name, value }) => { const driver = stateManager.getDriver(); const cookieService = new CookieService(driver); await cookieService.addCookieByName(name, value); return { content: [{ type: 'text', text: `Added cookie: ${name}` }], }; } );
- src/services/cookieService.ts:16-18 (helper)Core helper method in CookieService that adds the cookie to the browser using Selenium WebDriver.manage().addCookieasync addCookieByName(name: string, value: string): Promise<void> { await this.driver.manage().addCookie({ name, value }); }