Skip to main content
Glama

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
NameRequiredDescriptionDefault
nameYesName of the cookie to add
valueYesValue of the cookie to add

Implementation Reference

  • The handler function for the browser_add_cookie_by_name tool, which instantiates CookieService and calls addCookieByName
    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}` }],
      };
    }
  • 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'),
    },
  • Registration of the browser_add_cookie_by_name tool using server.tool, including description, schema, and handler
    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}` }],
        };
      }
    );
  • Core helper method in CookieService that adds the cookie to the browser using Selenium WebDriver.manage().addCookie
    async addCookieByName(name: string, value: string): Promise<void> {
      await this.driver.manage().addCookie({ name, value });
    }

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/pshivapr/selenium-mcp'

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