browser_wait_for
Wait for text to appear or disappear, or delay for a set time, to synchronize browser actions.
Instructions
Wait for text to appear or disappear or a specified time to pass
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| time | No | The time to wait in seconds | |
| text | No | The text to wait for | |
| textGone | No | The text to wait for to disappear |
Implementation Reference
- src/tools/wait.ts:35-65 (handler)Handler function for browser_wait_for. Waits for a specified time, for text to appear, or for text to disappear.
handle: async (context, params) => { if (!params.text && !params.textGone && !params.time) throw new Error('Either time, text or textGone must be provided'); const code: string[] = []; if (params.time) { code.push(`await new Promise(f => setTimeout(f, ${params.time!} * 1000));`); await new Promise(f => setTimeout(f, Math.min(10000, params.time! * 1000))); } const tab = context.currentTabOrDie(); const locator = params.text ? tab.page.getByText(params.text).first() : undefined; const goneLocator = params.textGone ? tab.page.getByText(params.textGone).first() : undefined; if (goneLocator) { code.push(`await page.getByText(${JSON.stringify(params.textGone)}).first().waitFor({ state: 'hidden' });`); await goneLocator.waitFor({ state: 'hidden' }); } if (locator) { code.push(`await page.getByText(${JSON.stringify(params.text)}).first().waitFor({ state: 'visible' });`); await locator.waitFor({ state: 'visible' }); } return { code, captureSnapshot, waitForNetwork: false, }; }, - src/tools/wait.ts:23-33 (schema)Input schema for browser_wait_for defining optional time (seconds), text, and textGone parameters.
schema: { name: 'browser_wait_for', title: 'Wait for', description: 'Wait for text to appear or disappear or a specified time to pass', inputSchema: z.object({ time: z.coerce.number().optional().describe('The time to wait in seconds'), text: z.string().optional().describe('The text to wait for'), textGone: z.string().optional().describe('The text to wait for to disappear'), }), type: 'readOnly', }, - src/tools.ts:35-49 (registration)Registration of wait tool (including browser_wait_for) in snapshotTools array via wait(true).
export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...wait(true), - src/tools.ts:52-65 (registration)Registration of wait tool (including browser_wait_for) in visionTools array via wait(false).
export const visionTools: Tool<any>[] = [ ...common(false), ...console, ...dialogs(false), ...files(false), ...install, ...keyboard(false), ...navigate(false), ...network, ...pdf, ...tabs(false), ...testing, ...vision, ...wait(false), - src/tools/tool.ts:23-68 (schema)ToolSchema type definition used by browser_wait_for schema.
export type ToolSchema<Input extends InputType> = { name: string; title: string; description: string; inputSchema: Input; type: 'readOnly' | 'destructive'; }; type InputType = z.Schema; export type FileUploadModalState = { type: 'fileChooser'; description: string; fileChooser: playwright.FileChooser; }; export type DialogModalState = { type: 'dialog'; description: string; dialog: playwright.Dialog; }; export type ModalState = FileUploadModalState | DialogModalState; export type ToolActionResult = { content?: (ImageContent | TextContent)[] } | undefined | void; export type ToolResult = { code: string[]; action?: () => Promise<ToolActionResult>; captureSnapshot: boolean; waitForNetwork: boolean; resultOverride?: ToolActionResult; }; export type Tool<Input extends InputType = InputType> = { capability: ToolCapability; schema: ToolSchema<Input>; clearsModalState?: ModalState['type']; handle: (context: Context, params: z.output<Input>) => Promise<ToolResult>; }; export type ToolFactory = (snapshot: boolean) => Tool<any>; export function defineTool<Input extends InputType>(tool: Tool<Input>): Tool<Input> { return tool; }