Skip to main content
Glama
Angeluis001

Playwright MCP

by Angeluis001

browser_handle_dialog

Accept or dismiss browser dialogs during web automation to manage pop-ups, alerts, and prompts in Playwright-based testing.

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 executes the tool logic: finds the dialog modal state, accepts or dismisses it based on parameters, clears the state, and returns internal code snippet.
    handle: async (context, params) => {
      const dialogState = context.modalStates().find(state => state.type === 'dialog');
      if (!dialogState)
        throw new Error('No dialog visible');
    
      if (params.accept)
        await dialogState.dialog.accept(params.promptText);
      else
        await dialogState.dialog.dismiss();
    
      context.clearModalState(dialogState);
    
      const code = [
        `// <internal code to handle "${dialogState.dialog.type()}" dialog>`,
      ];
    
      return {
        code,
        captureSnapshot,
        waitForNetwork: false,
      };
    },
  • Input schema and metadata definition for the browser_handle_dialog tool using Zod.
    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:35-50 (registration)
    Registration of browser_handle_dialog by spreading dialogs(true) into the snapshotTools array.
    export const snapshotTools: Tool<any>[] = [
      ...common(true),
      ...console,
      ...dialogs(true),
      ...files(true),
      ...install,
      ...keyboard(true),
      ...navigate(true),
      ...network,
      ...pdf,
      ...screenshot,
      ...snapshot,
      ...tabs(true),
      ...testing,
      ...wait(true),
    ];
  • src/tools.ts:52-66 (registration)
    Registration of browser_handle_dialog by spreading dialogs(false) into the visionTools array.
    export const visionTools: Tool<any>[] = [
      ...common(false),
      ...console,
      ...dialogs(false),
      ...files(false),
      ...install,
      ...keyboard(false),
      ...navigate(false),
      ...network,
      ...pdf,
      ...tabs(false),
      ...testing,
      ...vision,
      ...wait(false),
    ];

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/Angeluis001/playwright-mcp'

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