browser_add_cookie_by_name
Add a cookie to the browser by specifying its name and value for web automation and testing purposes.
Instructions
Add a cookie to the browser
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Name of the cookie to add | |
| value | Yes | Value of the cookie to add |
Input Schema (JSON Schema)
{
"properties": {
"name": {
"description": "Name of the cookie to add",
"type": "string"
},
"value": {
"description": "Value of the cookie to add",
"maxLength": 4096,
"minLength": 1,
"type": "string"
}
},
"required": [
"name",
"value"
],
"type": "object"
}
Implementation Reference
- src/tools/cookieTools.ts:32-47 (registration)Registration of the 'browser_add_cookie_by_name' tool, including description, Zod input schema for 'name' and 'value', and the inline handler function that uses CookieService to add the cookie.server.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/tools/cookieTools.ts:35-38 (schema)Zod schema defining the input parameters for the tool.{ 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:39-46 (handler)Handler function that executes the tool logic by retrieving the browser driver, instantiating CookieService, adding the cookie, and returning a text response.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)Helper method in CookieService that performs the actual cookie addition using Selenium WebDriver's manage().addCookie().async addCookieByName(name: string, value: string): Promise<void> { await this.driver.manage().addCookie({ name, value }); }
- src/tools/index.ts:12-12 (registration)Higher-level registration call to registerCookieTools within registerAllTools.registerCookieTools(server, stateManager);