wait_for
Pause execution until specified text or CSS selector becomes visible in the browser, with configurable timeout to synchronize page state changes.
Instructions
Wait for visible text or a CSS selector to appear on the page.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| text | No | ||
| selector | No | ||
| timeoutMs | No |
Implementation Reference
- src/index.ts:313-324 (handler)The handler function for the 'wait_for' tool. It calls requirePage() to get the active page, then waits for either visible text (using getByText) or a CSS selector (using locator) to appear within a configurable timeout (default 10s). Returns {ok: true, url: currentUrl} on success.
async function waitFor(args: { text?: string; selector?: string; timeoutMs?: number }) { const p = requirePage(); const timeout = args.timeoutMs ?? 10000; if (args.text) { await p.getByText(args.text).first().waitFor({ timeout }); } else if (args.selector) { await p.locator(args.selector).first().waitFor({ timeout }); } else { throw new Error('Provide {text} or {selector}.'); } return { ok: true, url: p.url() }; } - src/index.ts:424-434 (schema)The tool registration entry including input schema for wait_for. Defines properties: text (string), selector (string), timeoutMs (number). No required fields — the handler enforces that at least one of text/selector must be provided.
name: 'wait_for', description: 'Wait for visible text or a CSS selector to appear on the page.', inputSchema: { type: 'object', properties: { text: { type: 'string' }, selector: { type: 'string' }, timeoutMs: { type: 'number' }, }, }, }, - src/index.ts:469-469 (registration)The dispatch case in the CallToolRequestSchema handler that routes 'wait_for' requests to the waitFor function.
case 'wait_for': result = await waitFor(args as { text?: string; selector?: string; timeoutMs?: number }); break;