Skip to main content
Glama
b3nw
by b3nw

Wait for Element

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)
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions waiting for an element to appear but fails to specify what happens on timeout (e.g., error or return), if it polls continuously, or any performance implications. This leaves significant gaps in understanding the tool's behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, clear sentence with no wasted words. It is front-loaded and efficiently conveys the core purpose without unnecessary details, making it highly concise and well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (waiting with timeout), lack of annotations, and no output schema, the description is incomplete. It does not cover error handling, return values, or interaction with page state, which are crucial for effective use in a browser automation context.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 0%, so the description must compensate for undocumented parameters. It implies a 'selector' parameter but does not explain its format (e.g., CSS selector) or the 'timeout' parameter's unit (e.g., milliseconds). This adds minimal meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('wait for') and resource ('element'), specifying that it waits for an element to appear on a page. However, it does not explicitly differentiate from sibling tools like browser_navigate or browser_refresh, which might also involve waiting implicitly, so it falls short of a perfect score.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It does not mention scenarios like waiting after navigation or before interacting with elements, nor does it reference sibling tools for context, leaving usage unclear.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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