Skip to main content
Glama
livoras

Better Playwright MCP

by livoras

waitForSelector

Pause execution until a specified element, identified by a CSS selector or XPath, appears on the webpage, with configurable timeout and state conditions for precise control.

Instructions

等待指定选择器的元素出现

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pageIdYes页面ID
selectorYesCSS选择器或xp引用值
stateNo等待的状态(默认visible)
timeoutNo超时时间(毫秒,默认30000)

Implementation Reference

  • Core handler function that implements waitForSelector by calling Playwright's page.waitForSelector on the specified page.
    async waitForSelector(pageId: string, selector: string, options?: any) {
      const pageInfo = this.pages.get(pageId);
      if (!pageInfo) {
        throw new Error(`Page ${pageId} not found`);
      }
      
      await pageInfo.page.waitForSelector(selector, options);
    }
  • HTTP endpoint registration that exposes the waitForSelector functionality via POST /api/pages/:pageId/wait-selector.
    this.app.post('/api/pages/:pageId/wait-selector', async (req: Request, res: Response) => {
      try {
        const { pageId } = req.params;
        const { selector, options } = req.body;
        await this.waitForSelector(pageId, selector, options);
        res.json({ success: true });
      } catch (error: any) {
        res.status(500).json({ error: error.message });
      }
    });

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/livoras/better-playwright-mcp'

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