browser_handle_dialog
Accept or dismiss browser dialogs during automated web testing. Manage pop-ups, alerts, and prompts to maintain test flow.
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)The handler function implements the core logic for handling browser dialogs. It finds the current dialog state, clears it, and either accepts 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)The schema definition for the browser_handle_dialog tool, including name, title, description, input schema using Zod, and 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:53-55 (registration)Exports the defined tool for registration in the MCP tools system.export default [ handleDialog, ];