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 ProcessLauncher

From Leeroopedia

Template:Implementation Page

Overview

ProcessLauncher manages browser process lifecycle including launch, signal handling, graceful shutdown, and temporary directory cleanup.

Description

This module provides:

  • launchProcess -- launches a child process with comprehensive lifecycle management including:
 * Signal handling (SIGINT, SIGTERM, SIGHUP) with configurable behavior
 * Graceful close with timeout-based fallback to forced kill
 * Temporary directory cleanup after process exit
 * stdout/stderr line-by-line logging
  • gracefullyCloseAll -- closes all tracked browser processes
  • gracefullyProcessExitDoNotHang -- exits the Node.js process with a 30-second safety timeout

The module maintains global sets of graceful close and kill functions to ensure all browser processes are cleaned up on exit.

Usage

Used by all browser type implementations to launch browser processes and by the test runner for cleanup.

Code Reference

Source Location

packages/playwright-core/src/server/utils/processLauncher.ts (280 lines)

Key Signatures

export type LaunchProcessOptions = {
  command: string;
  args?: string[];
  env?: NodeJS.ProcessEnv;
  shell?: boolean;
  handleSIGINT?: boolean;
  handleSIGTERM?: boolean;
  handleSIGHUP?: boolean;
  stdio: 'pipe' | 'stdin';
  tempDirectories: string[];
  cwd?: string;
  attemptToGracefullyClose: () => Promise<any>;
  onExit: (exitCode: number | null, signal: string | null) => void;
  log: (message: string) => void;
};

export async function launchProcess(options: LaunchProcessOptions): Promise<{
  launchedProcess: childProcess.ChildProcess;
  gracefullyClose: () => Promise<void>;
  kill: () => Promise<void>;
}>;

export const gracefullyCloseSet: Set<() => Promise<void>>;
export async function gracefullyCloseAll(): Promise<void>;
export function gracefullyProcessExitDoNotHang(code: number, onExit?: () => Promise<void>): void;

Import

import { launchProcess, gracefullyCloseAll } from './server/utils/processLauncher';

I/O Contract

Inputs

  • Command, arguments, environment, and lifecycle callbacks
  • Temporary directories for cleanup

Outputs

  • Launched child process with graceful close and kill functions
  • Automatic cleanup of temporary directories on exit

Related Pages

Page Connections

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