Skip to main content
Glama

browser_handle_dialog

Handle browser dialogs during automation by accepting or dismissing them, and optionally providing text for prompt dialogs.

Instructions

Handle a dialog

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
acceptYesWhether to accept the dialog.
promptTextNoThe text of the prompt in case of a prompt dialog.

Implementation Reference

  • The handler function that locates the current dialog modal state on the tab, clears it, and either accepts the dialog with optional prompt text or dismisses it based on the input parameters.
    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(); }); },
  • The Zod schema definition for the tool, specifying the name 'browser_handle_dialog' and input parameters: boolean 'accept' and optional string 'promptText'.
    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', },
  • Local registration of the tool using defineTabTool, which combines schema, handler, and exports the tool instance.
    const handleDialog = defineTabTool({ capability: 'core', 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', }, 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(); }); }, clearsModalState: 'dialog', }); export default [ handleDialog, ];
  • src/tools.ts:36-52 (registration)
    Global registration by importing and spreading the dialogs tools (including browser_handle_dialog) into the allTools array.
    export const allTools: Tool<any>[] = [ ...common, ...console, ...dialogs, ...evaluate, ...files, ...install, ...keyboard, ...navigate, ...network, ...mouse, ...pdf, ...screenshot, ...snapshot, ...tabs, ...wait, ];
  • Helper function defineTabTool that wraps tab-specific tools, adding validation for modal states before invoking the handler.
    export function defineTabTool<Input extends z.Schema>(tool: TabTool<Input>): Tool<Input> { return { ...tool, handle: async (context, params, response) => { const tab = context.currentTabOrDie(); const modalStates = tab.modalStates().map(state => state.type); if (tool.clearsModalState && !modalStates.includes(tool.clearsModalState)) throw new Error(`The tool "${tool.schema.name}" can only be used when there is related modal state present.\n` + tab.modalStatesMarkdown().join('\n')); if (!tool.clearsModalState && modalStates.length) throw new Error(`Tool "${tool.schema.name}" does not handle the modal state.\n` + tab.modalStatesMarkdown().join('\n')); return tool.handle(tab, params, response); }, }; }

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/nzjami/mcpPlaywright'

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