Skip to main content
Glama

browser_wait_for

Wait for a specific element to appear on a webpage during automation, ensuring reliable interaction by pausing execution until the element is present or a timeout occurs.

Instructions

Wait for an element to appear on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes
timeoutNo

Implementation Reference

  • The handler function for the 'browser_wait_for' tool. It validates input parameters using Zod, ensures the Playwright browser is connected, retrieves the current page, and waits for the specified selector to appear using page.waitForSelector with optional timeout. Returns success or error message.
    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)
    Registers the 'browser_wait_for' tool with the MCP server, including title, description, inline input schema, and the 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 input parameters of the browser_wait_for tool: selector (required string) and timeout (optional number, default 30000). Also used for TypeScript type inference.
    export const BrowserWaitForInputSchema = z.object({ selector: z.string(), timeout: z.number().optional().default(30000) });

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