browser_handle_dialog
Automate dialog handling in web browsers by accepting or dismissing alerts, prompts, or confirmations using structured input for precise control during 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-48 (handler)The handler function that finds the current dialog modal state, clears it, and either accepts or dismisses the dialog based on the 'accept' parameter, with optional prompt text.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)Defines the tool schema including name 'browser_handle_dialog', input parameters 'accept' (boolean) and optional 'promptText' (string), marked as destructive.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:36-52 (registration)Registers the tool by including the exported dialogs array (containing browser_handle_dialog) in the main allTools export.export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];
- src/tools.ts:39-39 (registration)Spreads the imported dialogs tools into the allTools array, registering browser_handle_dialog....dialogs,
- src/tools.ts:19-19 (registration)Imports the dialogs.ts module which exports the browser_handle_dialog tool.import dialogs from './tools/dialogs.js';