browser_handle_dialog
Manage browser dialogs by accepting or declining them and providing prompt text when needed, using Playwright MCP server for automated web interactions.
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 asynchronous handler function that implements the core logic of the 'browser_handle_dialog' tool. It locates the current dialog modal state, accepts or dismisses the dialog based on the 'accept' parameter, clears the modal state, and returns a response with internal code comment and no network wait.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)The schema definition for the 'browser_handle_dialog' tool, specifying the name, title, description, Zod input schema (accept boolean and optional promptText), 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.ts:39-39 (registration)Registration of the 'browser_handle_dialog' tool factory (with captureSnapshot=true) into the snapshotTools array....dialogs(true),
- src/tools.ts:57-57 (registration)Registration of the 'browser_handle_dialog' tool factory (with captureSnapshot=false) into the visionTools array....dialogs(false),
- src/tools/dialogs.ts:60-62 (registration)Export of the tool factory function for 'browser_handle_dialog', which returns the defined tool based on captureSnapshot parameter, used in registrations above.export default (captureSnapshot: boolean) => [ handleDialog(captureSnapshot), ];