Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

handleDialog

Manages browser dialog interactions like alerts, confirms, and prompts by accepting or dismissing them and entering text when needed.

Instructions

Handle browser dialogs (alerts, confirms, prompts)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
acceptYesWhether to accept (true) or dismiss (false) the dialog
promptTextNoText to enter in prompt dialogs (optional)

Implementation Reference

  • Core handler implementation in PlaywrightController that sets up a one-time listener for dialog events and handles accept/dismiss with optional prompt text.
    async handleDialog(accept: boolean, promptText?: string): Promise<void> { try { if (!this.isInitialized() || !this.state.page) { throw new Error('Browser not initialized'); } this.log('Setting up dialog handler', { accept, promptText }); this.state.page.once('dialog', async dialog => { this.log('Dialog detected', { type: dialog.type(), message: dialog.message() }); if (accept) { await dialog.accept(promptText); } else { await dialog.dismiss(); } this.log('Dialog handled'); }); } catch (error: any) { console.error('Handle dialog error:', error); throw new BrowserError('Failed to handle dialog', 'Check if there is a dialog to handle'); } }
  • Tool schema defining the input parameters: accept (required boolean) and optional promptText (string).
    const HANDLE_DIALOG_TOOL: Tool = { name: "handleDialog", description: "Handle browser dialogs (alerts, confirms, prompts)", inputSchema: { type: "object", properties: { accept: { type: "boolean", description: "Whether to accept (true) or dismiss (false) the dialog" }, promptText: { type: "string", description: "Text to enter in prompt dialogs (optional)" } }, required: ["accept"] } };
  • src/server.ts:543-543 (registration)
    Registration of the handleDialog tool in the tools object passed to MCP server capabilities.
    handleDialog: HANDLE_DIALOG_TOOL,
  • src/server.ts:886-897 (registration)
    MCP callTool request handler case that validates input and delegates to the Playwright controller's handleDialog method.
    case 'handleDialog': { if (typeof args.accept !== 'boolean') { return { content: [{ type: "text", text: "Accept parameter is required" }], isError: true }; } await playwrightController.handleDialog(args.accept, args.promptText as string); return { content: [{ type: "text", text: "Dialog handler set successfully" }] }; }

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/jomon003/PlayMCP'

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