browser_handle_dialog
Accept or dismiss browser dialogs, including alerts, confirmations, and prompts, with optional prompt text input.
Instructions
Handle a dialog
Input 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:20-58 (handler)The handler function that executes the 'browser_handle_dialog' tool logic. It finds the current dialog modal state, accepts or dismisses it (with optional prompt text), clears the modal state, and returns the result.
const handleDialog: ToolFactory = captureSnapshot => defineTool({ capability: 'core', schema: { name: 'browser_handle_dialog', title: 'Handle a dialog', description: 'Handle a dialog', inputSchema: z.object({ accept: z.coerce.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 (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, }; }, clearsModalState: 'dialog', }); - src/tools/dialogs.ts:23-32 (schema)The schema definition for the tool: defines name 'browser_handle_dialog', input parameters (accept: boolean, promptText: optional string), and marks it as 'destructive'.
schema: { name: 'browser_handle_dialog', title: 'Handle a dialog', description: 'Handle a dialog', inputSchema: z.object({ accept: z.coerce.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 the tool factory function that creates the browser_handle_dialog tool, which is then spread into the tool arrays in src/tools.ts.
export default (captureSnapshot: boolean) => [ handleDialog(captureSnapshot), ]; - src/tools.ts:35-50 (registration)Registers the dialog tool in both snapshotTools and visionTools arrays by spreading the dialogs factory output.
export const snapshotTools: Tool<any>[] = [ ...common(true), ...console, ...dialogs(true), ...files(true), ...install, ...keyboard(true), ...navigate(true), ...network, ...pdf, ...screenshot, ...snapshot, ...tabs(true), ...testing, ...wait(true), ]; - src/context.ts:63-73 (helper)Helper methods on the Context class that manage modal state (including dialogs): modalStates() retrieves them, setModalState() adds one, clearModalState() removes one.
modalStates(): ModalState[] { return this._modalStates; } setModalState(modalState: ModalState, inTab: Tab) { this._modalStates.push({ ...modalState, tab: inTab }); } clearModalState(modalState: ModalState) { this._modalStates = this._modalStates.filter(state => state !== modalState); }