browser_handle_dialog
Accept or dismiss browser dialogs during web automation, including handling prompt dialogs by providing text input when required.
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 implements the core logic of the 'browser_handle_dialog' tool. It locates the current dialog, accepts or dismisses it based on the 'accept' parameter and optional 'promptText', clears the modal state, and returns an execution result.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)Zod schema definition for the 'browser_handle_dialog' tool, specifying the input parameters: 'accept' (boolean) and optional 'promptText' (string).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)Tool factory export that produces the 'browser_handle_dialog' tool, parameterized by captureSnapshot flag.export default (captureSnapshot: boolean) => [ handleDialog(captureSnapshot), ];
- src/tools.ts:36-52 (registration)Main registration of snapshot tools, including the browser_handle_dialog via spread of dialogs(true).export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...video, ...wait(true), ];
- src/tools.ts:54-69 (registration)Main registration of vision tools, including the browser_handle_dialog via spread of dialogs(false).export const visionTools: Tool<any>[] = [ ...common(false), ...console, ...dialogs(false), ...files(false), ...install, ...keyboard(false), ...navigate(false), ...network, ...pdf, ...tabs(false), ...testing, ...video, ...vision, ...wait(false), ];