browser_handle_dialog
Handle browser dialogs by accepting or inputting text, enabling automated interaction with prompts, alerts, or confirmations during web testing with Playwright and Cloudflare integration.
Instructions
Handle a dialog
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accept | Yes | Whether to accept the dialog. | |
| promptText | No | The text of the prompt in case of a prompt dialog. |
Implementation Reference
- src/tools/dialogs.ts:34-55 (handler)The handler function that finds the current dialog state and either accepts it with optional prompt text or dismisses it, then clears the modal state and returns a code snippet.handle: async (context, params) => { const dialogState = context.modalStates().find(state => state.type === 'dialog'); if (!dialogState) throw new Error('No dialog visible'); if (params.accept) await dialogState.dialog.accept(params.promptText); else await dialogState.dialog.dismiss(); context.clearModalState(dialogState); const code = [ `// <internal code to handle "${dialogState.dialog.type()}" dialog>`, ]; return { code, captureSnapshot, waitForNetwork: false, }; },
- src/tools/dialogs.ts:23-32 (schema)Schema definition for the browser_handle_dialog tool, specifying input parameters 'accept' (boolean) and optional 'promptText' (string), marked as destructive.schema: { name: 'browser_handle_dialog', title: 'Handle a dialog', description: 'Handle a dialog', inputSchema: z.object({ accept: z.coerce.boolean().describe('Whether to accept the dialog.'), promptText: z.string().optional().describe('The text of the prompt in case of a prompt dialog.'), }), type: 'destructive', },
- src/tools.ts:35-50 (registration)Includes dialogs(true) which registers browser_handle_dialog for snapshot (non-vision) mode.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-66 (registration)Includes dialogs(false) which registers browser_handle_dialog for vision mode.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), ];