browser_handle_dialog
Manage browser dialogs by accepting or dismissing them and optionally inputting text for prompt dialogs using Playwright MCP's automation capabilities.
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)Executes the tool logic: finds the dialog state, accepts or dismisses based on 'accept' param and optional promptText, clears modal state, returns 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)Defines the input schema and metadata for the 'browser_handle_dialog' tool using Zod.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:60-62 (registration)Exports a factory function that returns the tool for inclusion in tool registries.export default (captureSnapshot: boolean) => [ handleDialog(captureSnapshot), ];
- src/tools.ts:38-38 (registration)Registers the tool (via dialogs(true)) in the snapshotTools array....dialogs(true),
- src/tools.ts:55-55 (registration)Registers the tool (via dialogs(false)) in the visionTools array....dialogs(false),