Skip to main content
Glama
Angeluis001

Playwright MCP

by Angeluis001

browser_click

Click elements on web pages to automate browser interactions, supporting single or double clicks with modifier keys and specific mouse buttons.

Instructions

Perform click on a web page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
elementYesHuman-readable element description used to obtain permission to interact with the element
refYesExact target element reference from the page snapshot
doubleClickNoWhether to perform a double click instead of a single click
buttonNoButton to click, defaults to left
modifiersNoModifier keys to press

Implementation Reference

  • The handler function that executes the browser_click tool. It retrieves the locator from the current tab's snapshot using the provided params and performs the click action via Playwright, while also generating explanatory code and configuring post-action behavior.
    handle: async (context, params) => {
      const tab = context.currentTabOrDie();
      const locator = tab.snapshotOrDie().refLocator(params);
    
      const code = [
        `// Click ${params.element}`,
        `await page.${await generateLocator(locator)}.click();`
      ];
    
      return {
        code,
        action: () => locator.click(),
        captureSnapshot: true,
        waitForNetwork: true,
      };
    },
  • The schema definition for the browser_click tool, including name, title, description, input schema (elementSchema), and type.
    schema: {
      name: 'browser_click',
      title: 'Click',
      description: 'Perform click on a web page',
      inputSchema: elementSchema,
      type: 'destructive',
    },
  • The complete tool definition and registration using defineTool, which is then exported for inclusion in the tools registry.
    const click = defineTool({
      capability: 'core',
      schema: {
        name: 'browser_click',
        title: 'Click',
        description: 'Perform click on a web page',
        inputSchema: elementSchema,
        type: 'destructive',
      },
    
      handle: async (context, params) => {
        const tab = context.currentTabOrDie();
        const locator = tab.snapshotOrDie().refLocator(params);
    
        const code = [
          `// Click ${params.element}`,
          `await page.${await generateLocator(locator)}.click();`
        ];
    
        return {
          code,
          action: () => locator.click(),
          captureSnapshot: true,
          waitForNetwork: true,
        };
      },
    });
  • The Zod schema for the input parameters used by browser_click (and other tools), defining element description and ref.
    const elementSchema = z.object({
      element: z.string().describe('Human-readable element description used to obtain permission to interact with the element'),
      ref: z.string().describe('Exact target element reference from the page snapshot'),
    });
  • Exports the browser_click tool (as 'click') along with other snapshot-related tools for inclusion in the main tools array.
    export default [
      snapshot,
      click,
      drag,
      hover,
      type,
      selectOption,
    ];

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/Angeluis001/playwright-mcp'

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