handle_dialog
Accept or dismiss browser dialogs during Chrome automation to manage pop-ups and alerts that interrupt testing workflows.
Instructions
If a browser dialog was opened, use this command to handle it
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | Whether to dismiss or accept the dialog | |
| promptText | No | Optional prompt text to enter into the dialog. |
Implementation Reference
- src/tools/pages.ts:202-233 (handler)The handler function for the 'handle_dialog' tool. It retrieves the current dialog from context, then accepts or dismisses it based on the action parameter, optionally entering prompt text for accept. Clears the dialog and includes pages in response.
handler: async (request, response, context) => { const dialog = context.getDialog(); if (!dialog) { throw new Error('No open dialog found'); } switch (request.params.action) { case 'accept': { try { await dialog.accept(request.params.promptText); } catch (err) { // Likely already handled by the user outside of MCP. logger(err); } response.appendResponseLine('Successfully accepted the dialog'); break; } case 'dismiss': { try { await dialog.dismiss(); } catch (err) { // Likely already handled. logger(err); } response.appendResponseLine('Successfully dismissed the dialog'); break; } } context.clearDialog(); response.setIncludePages(true); }, - src/tools/pages.ts:193-201 (schema)Input schema for the 'handle_dialog' tool using Zod. Defines 'action' as enum ['accept', 'dismiss'] and optional 'promptText' string.
schema: { action: z .enum(['accept', 'dismiss']) .describe('Whether to dismiss or accept the dialog'), promptText: z .string() .optional() .describe('Optional prompt text to enter into the dialog.'), }, - src/tools/pages.ts:186-234 (registration)Registration of the 'handle_dialog' tool using defineTool, including name, description, annotations, schema, and handler.
export const handleDialog = defineTool({ name: 'handle_dialog', description: `If a browser dialog was opened, use this command to handle it`, annotations: { category: ToolCategories.INPUT_AUTOMATION, readOnlyHint: false, }, schema: { action: z .enum(['accept', 'dismiss']) .describe('Whether to dismiss or accept the dialog'), promptText: z .string() .optional() .describe('Optional prompt text to enter into the dialog.'), }, handler: async (request, response, context) => { const dialog = context.getDialog(); if (!dialog) { throw new Error('No open dialog found'); } switch (request.params.action) { case 'accept': { try { await dialog.accept(request.params.promptText); } catch (err) { // Likely already handled by the user outside of MCP. logger(err); } response.appendResponseLine('Successfully accepted the dialog'); break; } case 'dismiss': { try { await dialog.dismiss(); } catch (err) { // Likely already handled. logger(err); } response.appendResponseLine('Successfully dismissed the dialog'); break; } } context.clearDialog(); response.setIncludePages(true); }, });