Skip to main content
Glama
nzjami

Playwright MCP

by nzjami

browser_handle_dialog

Destructive

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);
        },
      };
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations provide readOnlyHint=false, destructiveHint=true, and openWorldHint=true, indicating this is a mutating, potentially destructive operation with open-ended effects. The description adds no behavioral context beyond these annotations—it doesn't explain what gets destroyed (e.g., dialog state, user input), what permissions are needed, or any rate limits. However, it doesn't contradict the annotations, so it meets the lower bar with annotations present.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

While concise with only three words, the description is under-specified rather than efficiently structured. It fails to front-load essential information and doesn't use its limited space to convey meaningful context. Every word should earn its place, but 'Handle a dialog' provides minimal value beyond the tool name itself.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with destructiveHint=true, no output schema, and complex browser interaction context, the description is incomplete. It doesn't explain what a 'dialog' refers to in the browser context, what the tool returns, error conditions, or how it fits with sibling tools. The annotations help but don't compensate for the lack of operational context in the description.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for both parameters (accept and promptText). The description adds no additional meaning about parameters beyond what the schema provides—it doesn't explain when promptText is required, what happens if accept is false, or how these parameters interact with different dialog types. This meets the baseline of 3 given the comprehensive schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Handle a dialog' is a tautology that merely restates the tool name, providing no specific information about what the tool actually does. It doesn't specify what type of dialog (e.g., JavaScript alert, confirmation, prompt) or what handling entails, nor does it distinguish this from sibling tools like browser_click or browser_press_key that might also interact with browser UI elements.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines1/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention what triggers a dialog, when this tool is appropriate, or how it relates to sibling tools like browser_evaluate or browser_run_code that might generate dialogs. There's no context about prerequisites or timing considerations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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