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
| Name | Required | Description | Default |
|---|---|---|---|
| accept | Yes | Whether to accept (true) or dismiss (false) the dialog | |
| promptText | No | Text to enter in prompt dialogs (optional) |
Implementation Reference
- src/controllers/playwright.ts:723-743 (handler)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'); } }
- src/server.ts:372-389 (schema)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" }] }; }