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 Electron

From Leeroopedia
Knowledge Sources
Domains Desktop App Testing, Electron Framework
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for automating Electron desktop applications provided by the Playwright library.

Description

The `ElectronApplication` class extends `SdkObject` and manages an Electron application process for testing. It connects to the Electron app's Chromium browser via a CDP connection (`CRConnection`), wraps the browser context (`CRBrowserContext`), and provides access to individual windows as Playwright `Page` objects. The class handles Electron-specific features like evaluating JavaScript in the main Electron process, accessing `BrowserWindow` handles, and monitoring console output. It emits `Close` and `Console` events. The `Electron` class serves as the launcher, managing process startup with custom arguments, environment variables, and proper signal handling, and establishes the CDP WebSocket connection to the running Electron process.

Usage

Use this module when automating Electron desktop applications for testing. It enables launching Electron apps, interacting with their windows via the Playwright Page API, and evaluating code in the Electron main process.

Code Reference

Source Location

Signature

export class ElectronApplication extends SdkObject {
  static Events: { Close: 'close', Console: 'console' };

  private _browserContext: CRBrowserContext;
  private _process: childProcess.ChildProcess;

  async browserWindow(page: Page): Promise<JSHandle<BrowserWindow>>;
  async evaluate<R>(expression: string | Function): Promise<R>;
  async evaluateHandle<R>(expression: string | Function): Promise<JSHandle<R>>;
  context(): BrowserContext;
  windows(): Page[];
  async close(): Promise<void>;
}

export class Electron extends SdkObject {
  async launch(options: channels.ElectronLaunchParams): Promise<ElectronApplication>;
}

Import

import { Electron, ElectronApplication } from '../server/electron/electron';

I/O Contract

Inputs

Name Type Required Description
options.executablePath string No Path to Electron executable (defaults to node_modules/.bin/electron)
options.args string[] No Command-line arguments for the Electron app
options.cwd string No Working directory for the Electron process
options.env object No Environment variables for the Electron process
options.timeout number No Launch timeout in milliseconds

Outputs

Name Type Description
ElectronApplication ElectronApplication Launched Electron app instance
windows Page[] Array of open Electron windows as Page objects
BrowserWindow handle JSHandle<BrowserWindow> Handle to the Electron BrowserWindow for a page

Usage Examples

import { Electron } from 'playwright-core/lib/server/electron/electron';

const electron = new Electron(parentSdkObject);
const app = await electron.launch({
  executablePath: '/path/to/electron',
  args: ['./main.js'],
});

// Get first window
const window = app.windows()[0];
await window.click('button#submit');

// Evaluate in main process
const result = await app.evaluate(() => process.env.HOME);

// Access BrowserWindow
const bw = await app.browserWindow(window);

await app.close();

Related Pages

Page Connections

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