/** * Chrome Launcher * Utilities for launching Chrome with debugging enabled */ import type { PortReserver } from './port-reserver.js'; export type ChromeCloseReason = 'inactivity' | 'manual' | 'crash' | 'external' | 'signal' | 'unknown'; export interface ChromeCloseEvent { port: number; pid: number; reason: ChromeCloseReason; timestamp: Date; exitCode?: number | null; signal?: string | null; } export type ChromeExitCallback = (event: ChromeCloseEvent) => void | Promise; export declare class ChromeLauncher { private chromeProcesses; private launchLocks; private lastCloseEvents; private maxCloseEvents; private pendingCloseReason; private onExitCallback; /** * Set a callback to be invoked when any Chrome process exits. * Used for cleanup (closing stale connections) and port re-reservation. */ setOnExitCallback(callback: ChromeExitCallback): void; /** * Get the Chrome executable path for the current platform */ private getChromePath; /** * Create Chrome preferences file that disables password manager popups * This is required because command-line flags alone don't reliably disable * the "Change your password" leak detection popup */ private createChromePreferences; /** * Check if a port is already in use using TCP connection */ private isPortInUse; /** * Wait for Chrome debugging port to become ready * Polls the /json/version endpoint until Chrome is inspectable */ private waitForChromeReady; /** * Launch Chrome with debugging enabled * Uses atomic release-and-launch to prevent race conditions * Waits for Chrome to actually bind to the port before resolving */ launch(port?: number, url?: string, portReserver?: PortReserver, headless?: boolean): Promise<{ port: number; pid: number; }>; /** * Internal method that performs the actual Chrome launch * Separated from launch() to allow mutex/locking logic */ private performLaunch; /** * Check if a process with the given PID is actually running * This handles the case where Chrome is killed externally (e.g., Activity Monitor, kill command) */ private isProcessAlive; /** * Check if Chrome is running on a specific port, or if any Chrome instance is running * This verifies the process is actually alive, not just tracked */ isRunning(port?: number): boolean; /** * Get all running Chrome ports */ getRunningPorts(): number[]; /** * Kill Chrome process(es) * If port is specified, kills only that instance. Otherwise kills all instances. * First attempts graceful shutdown with SIGTERM, then force kills with SIGKILL if needed */ kill(port?: number): Promise; /** * Kill a specific Chrome instance by port */ private killInstance; /** * Reset the launcher state (useful if Chrome was closed externally) */ reset(port?: number): void; /** * Record a Chrome close event */ private recordCloseEvent; /** * Get the last close events */ getLastCloseEvents(): ChromeCloseEvent[]; /** * Get Chrome launcher status for all instances * Verifies each process is actually alive and cleans up dead ones */ getStatus(): { instances: Array<{ port: number; pid: number; running: boolean; }>; lastCloseEvents: ChromeCloseEvent[]; }; /** * Set the pending close reason for a port (call before killing) */ setPendingCloseReason(port: number, reason: ChromeCloseReason): void; } //# sourceMappingURL=chrome-launcher.d.ts.map