Skip to main content
Glama
jomon003

PlayMCP Browser Automation Server

by jomon003

handleDialog

Control browser dialogs (alerts, confirms, prompts) by accepting, dismissing, or entering text. Simplify web automation workflows with precise dialog handling.

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

  • The core handler function that sets up a one-time listener for browser dialogs (alert, confirm, prompt), logging the event, and either accepting with optional prompt text or dismissing based on the accept parameter.
    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'); } }
  • Defines the tool schema with input validation: required 'accept' 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)
    Registers the handleDialog tool in the tools dictionary passed to MCP server capabilities.
    handleDialog: HANDLE_DIALOG_TOOL,
  • src/server.ts:886-897 (registration)
    Dispatches the tool call to the playwrightController.handleDialog method with input validation in the MCP callTool request handler.
    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