Skip to main content
Glama

browser_wait_for

Use this tool to pause execution until a specified web element appears on a page, ensuring interactions occur only when the element is present. Ideal for web automation tasks requiring precise timing and element availability.

Instructions

Wait for an element to appear on the page

Input Schema

NameRequiredDescriptionDefault
selectorYes
timeoutNo

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "selector": { "type": "string" }, "timeout": { "default": 30000, "type": "number" } }, "required": [ "selector" ], "type": "object" }

Implementation Reference

  • The handler function executes the browser_wait_for tool logic: validates input, connects to Playwright if needed, retrieves the current page, waits for the specified selector with optional timeout using page.waitForSelector, and returns appropriate success or error response.
    async (params: any) => { try { const input = z.object({ selector: z.string(), timeout: z.number().optional().default(30000) }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); await page.waitForSelector(input.selector, { timeout: input.timeout }); return { content: [{ type: 'text', text: `Element appeared: ${input.selector}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Wait for element failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } }
  • src/server.ts:233-270 (registration)
    The registration of the 'browser_wait_for' tool in the PlaywrightMcpServer.setupTools() method, including inline input schema definition, tool metadata, and the inline handler function.
    this.server.registerTool( 'browser_wait_for', { title: 'Wait for Element', description: 'Wait for an element to appear on the page', inputSchema: { selector: z.string(), timeout: z.number().optional().default(30000) } }, async (params: any) => { try { const input = z.object({ selector: z.string(), timeout: z.number().optional().default(30000) }).parse(params); await this.playwright.ensureConnected(); const page = this.playwright.getPage(); await page.waitForSelector(input.selector, { timeout: input.timeout }); return { content: [{ type: 'text', text: `Element appeared: ${input.selector}` }] }; } catch (error) { return { content: [{ type: 'text', text: `Wait for element failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Zod schema definition for the browser_wait_for tool input (matches the inline schema used in registration).
    export const BrowserWaitForInputSchema = z.object({ selector: z.string(), timeout: z.number().optional().default(30000) });
  • TypeScript type definition inferred from the BrowserWaitForInputSchema.
    export type BrowserWaitForInput = z.infer<typeof BrowserWaitForInputSchema>;

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

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