browser_handle_dialog
Automate dialog handling during web accessibility scans by accepting or dismissing prompts, ensuring uninterrupted WCAG compliance testing with Playwright and Axe-core.
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-48 (handler)Handler function that locates the current dialog modal state, clears it, and either accepts (with optional prompt text) or dismisses the dialog based on the input parameters.handle: async (tab, params, response) => { response.setIncludeSnapshot(); const dialogState = tab.modalStates().find(state => state.type === 'dialog'); if (!dialogState) throw new Error('No dialog visible'); tab.clearModalState(dialogState); await tab.waitForCompletion(async () => { if (params.accept) await dialogState.dialog.accept(params.promptText); else await dialogState.dialog.dismiss(); }); },
- src/tools/dialogs.ts:23-32 (schema)Schema definition for the tool, including name, title, description, Zod input schema for 'accept' boolean and optional 'promptText' string, and destructive type.schema: { name: 'browser_handle_dialog', title: 'Handle a dialog', description: 'Handle a dialog', inputSchema: z.object({ accept: z.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/dialogs.ts:20-51 (registration)Local registration of the tool using defineTabTool, which encapsulates schema, handler, capability, and modal state clearing behavior.const handleDialog = defineTabTool({ capability: 'core', schema: { name: 'browser_handle_dialog', title: 'Handle a dialog', description: 'Handle a dialog', inputSchema: z.object({ accept: z.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', }, handle: async (tab, params, response) => { response.setIncludeSnapshot(); const dialogState = tab.modalStates().find(state => state.type === 'dialog'); if (!dialogState) throw new Error('No dialog visible'); tab.clearModalState(dialogState); await tab.waitForCompletion(async () => { if (params.accept) await dialogState.dialog.accept(params.promptText); else await dialogState.dialog.dismiss(); }); }, clearsModalState: 'dialog', });
- src/tools.ts:38-56 (registration)Global registration where the dialogs tools (including browser_handle_dialog) are spread into the allTools array for export and use in the MCP protocol.export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...form, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ...verify, ];