Skip to main content
Glama

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
NameRequiredDescriptionDefault
actionYesWhether to dismiss or accept the dialog
promptTextNoOptional prompt text to enter into the dialog.

Implementation Reference

  • 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); },
  • 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.'), },
  • 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); }, });

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SHAY5555-gif/chrome-devtools-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server