Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

waitForSelector

Waits for a specific HTML element to appear on a webpage before proceeding, ensuring reliable automation by synchronizing with page loading and dynamic content.

Instructions

Wait for a specific selector to appear on the page

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
selectorYes
timeoutNoTimeout in milliseconds (default: 30000)

Implementation Reference

  • The core handler function implementing waitForSelector using Playwright's page.waitForSelector method, with error handling and logging.
    async waitForSelector(selector: string, timeout: number = 30000): Promise<void> {
      try {
        if (!this.isInitialized() || !this.state.page) {
          throw new Error('Browser not initialized');
        }
        this.log('Waiting for selector', { selector, timeout });
        await this.state.page.waitForSelector(selector, { timeout });
        this.log('Selector found');
      } catch (error: any) {
        console.error('Wait for selector error:', error);
        throw new BrowserError('Selector not found within timeout', 'Check if the selector appears on the page');
      }
    }
  • Input schema definition for the waitForSelector tool, specifying selector (required) and optional timeout.
    const WAIT_FOR_SELECTOR_TOOL: Tool = {
      name: "waitForSelector",
      description: "Wait for a specific selector to appear on the page",
      inputSchema: {
        type: "object",
        properties: {
          selector: { type: "string" },
          timeout: { 
            type: "number",
            description: "Timeout in milliseconds (default: 30000)"
          }
        },
        required: ["selector"]
      }
    };
  • src/server.ts:541-541 (registration)
    Registration of the waitForSelector tool in the tools object passed to MCP server capabilities.
    waitForSelector: WAIT_FOR_SELECTOR_TOOL,
  • src/server.ts:860-871 (registration)
    Dispatch handler in the callTool request handler switch statement that invokes the playwrightController's waitForSelector method.
    case 'waitForSelector': {
      if (!args.selector) {
        return {
          content: [{ type: "text", text: "Selector is required" }],
          isError: true
        };
      }
      await playwrightController.waitForSelector(args.selector as string, args.timeout as number);
      return {
        content: [{ type: "text", text: "Selector found successfully" }]
      };
    }
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 a selector to appear but omits critical details such as polling behavior, error handling (e.g., what happens if the selector doesn't appear), default timeout implications, or whether this is a blocking operation. This leaves significant gaps in understanding how the tool behaves in practice.

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, straightforward sentence with no wasted words. It front-loads the core purpose efficiently, making it easy to parse quickly without unnecessary elaboration.

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 (involving timing and DOM interactions), lack of annotations, no output schema, and incomplete parameter documentation, the description is insufficient. It doesn't address return values, error conditions, or interaction with other tools like navigation or user actions, leaving the agent with incomplete context for effective use.

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

Parameters3/5

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

Schema description coverage is 50% (only 'timeout' has a description), and the description adds no parameter-specific information beyond what's implied by the tool name. It doesn't explain what a 'selector' is or provide examples, nor does it clarify timeout behavior beyond the schema's default value. The description fails to compensate for the low schema coverage, resulting in minimal added value.

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 action ('wait for') and target ('specific selector to appear on the page'), making the purpose immediately understandable. However, it doesn't explicitly differentiate from sibling tools like 'waitForText', which serves a similar waiting function but for text content rather than selectors.

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 like 'waitForText' or other waiting mechanisms. It lacks context about typical use cases, prerequisites, or exclusions, leaving the agent to infer usage based on the tool name alone.

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/jomon003/PlayMCP'

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