Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

waitForSelector

Pause execution until a specified HTML element appears on the webpage, ensuring synchronization in browser automation tasks. Input includes a CSS selector and optional timeout.

Instructions

Wait for a specific selector to appear on the page

Input Schema

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

Implementation Reference

  • Core handler function implementing the waitForSelector tool logic using Playwright's page.waitForSelector method with logging and error handling.
    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'); } }
  • Dispatch handler in the MCP callTool request handler that validates input and delegates to the Playwright controller'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" }] }; }
  • Tool schema definition including input schema with required 'selector' parameter 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:555-565 (registration)
    Server initialization registering all tools (including waitForSelector via the 'tools' object) in MCP capabilities.
    const server = new Server( { name: "playmcp-browser", version: "1.0.0", }, { capabilities: { tools, }, } );
  • src/server.ts:541-541 (registration)
    Specific inclusion of the waitForSelector tool in the tools dictionary used for MCP registration.
    waitForSelector: WAIT_FOR_SELECTOR_TOOL,

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