Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright Server Dialog

From Leeroopedia
Knowledge Sources
Domains Server, Dialog
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for representing and handling JavaScript dialog boxes (alert, confirm, prompt, beforeunload) on the server side provided by the Playwright library.

Description

The `Dialog` class extends `SdkObject` and represents a browser dialog (alert, confirm, prompt, or beforeunload). It stores the dialog type, message text, default value (for prompts), and a handler callback. The `accept` and `dismiss` methods invoke the handler callback with appropriate parameters and mark the dialog as handled to prevent double-handling. The class exposes accessor methods for `page()`, `type()`, `message()`, and `defaultValue()`. The `DialogType` type union defines the four supported dialog types.

Usage

Use Server Dialog when Playwright encounters JavaScript dialogs during page automation and needs to represent them as server-side objects for the dispatcher layer.

Code Reference

Source Location

Signature

export type DialogType = 'alert' | 'beforeunload' | 'confirm' | 'prompt';

export class Dialog extends SdkObject {
  constructor(page: Page, type: DialogType, message: string, onHandle: OnHandle, defaultValue?: string);
  page(): Page;
  type(): string;
  message(): string;
  defaultValue(): string;
  async accept(promptText?: string): Promise<void>;
  async dismiss(): Promise<void>;
}

Import

import { Dialog } from '../server/dialog';
import type { DialogType } from '../server/dialog';

I/O Contract

Inputs

Name Type Required Description
page Page Yes The page that triggered the dialog
type DialogType Yes The type of dialog (alert, confirm, prompt, beforeunload)
message string Yes The dialog message text
onHandle OnHandle Yes Async callback to accept or dismiss the dialog in the browser
defaultValue string No Default value for prompt dialogs

Outputs

Name Type Description
(side effect) void Dialog accepted or dismissed in the browser

Usage Examples

import { Dialog } from '../server/dialog';

const dialog = new Dialog(page, 'prompt', 'Enter your name:', async (accept, text) => {
  // Browser-level dialog handling
}, 'default name');

console.log(dialog.type());         // 'prompt'
console.log(dialog.message());      // 'Enter your name:'
console.log(dialog.defaultValue()); // 'default name'
await dialog.accept('John');

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment