Skip to main content
Glama

browser_click

Automate clicking specific elements on web pages using CSS selectors for penetration testing, enhancing web application security assessments with precise browser interaction.

Instructions

Click an element on the page using CSS selector

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYesCSS selector for element to click

Implementation Reference

  • The main handler for the 'browser_click' tool. It uses Playwright's page.locator to click the element specified by the CSS selector. Includes error handling for strict mode violations by retrying on the first matching element and returns appropriate success/error messages.
    case ToolName.BrowserClick: try { await page.locator(args.selector).click(); return { content: [{ type: "text", text: `Clicked: ${args.selector}`, }], isError: false, }; } catch (error) { if((error as Error).message.includes("strict mode violation")) { console.log("Strict mode violation, retrying on first element..."); try { await page.locator(args.selector).first().click(); return { content: [{ type: "text", text: `Clicked: ${args.selector}`, }], isError: false, }; } catch (error) { return { content: [{ type: "text", text: `Failed (twice) to click ${args.selector}: ${(error as Error).message}`, }], isError: true, }; } } return { content: [{ type: "text", text: `Failed to click ${args.selector}: ${(error as Error).message}`, }], isError: true, }; }
  • index.ts:63-73 (registration)
    Registers the 'browser_click' tool in the TOOLS array, including its name, description, and input schema. This array is returned by the ListToolsRequest handler.
    { name: ToolName.BrowserClick, description: "Click an element on the page using CSS selector", inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector for element to click" }, }, required: ["selector"], }, },
  • Defines the input schema for the 'browser_click' tool, specifying that it requires a 'selector' string parameter.
    inputSchema: { type: "object", properties: { selector: { type: "string", description: "CSS selector for element to click" }, }, required: ["selector"],
  • Helper function called by the handler to ensure a browser and page instance are available before performing the click action.
    async function ensureBrowser() { if (!browser) { browser = await playwright.firefox.launch({ headless: false }); } if (!page) { page = await browser.newPage(); } page.on("console", (msg) => { const logEntry = `[${msg.type()}] ${msg.text()}`; consoleLogs.push(logEntry); server.notification({ method: "notifications/resources/updated", params: { uri: "console://logs" }, }); }); return page!; }

Other Tools

Related Tools

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/9olidity/MCP-Server-Pentest'

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