/** * Browser Pool - Manages a pool of warm browser sessions * * QA-INFRA-001: Addresses timeout issues like `browserContext.newPage: Target closed` * by maintaining warm, pre-initialized browser sessions with health monitoring. * * Features: * - Pre-warmed browser pool for faster first page loads * - Health checks to detect stale/hung sessions * - Auto-refresh sessions before they timeout * - Graceful degradation when pool is exhausted */ import type { Browser, BrowserContext, Page } from 'playwright'; import { type BrowserProvider, type BrowserProviderConfig } from './browser-providers.js'; export interface PooledSession { id: string; browser: Browser; context: BrowserContext; createdAt: number; lastUsedAt: number; lastHealthCheckAt: number; useCount: number; healthy: boolean; inUse: boolean; provider: BrowserProvider; slotReleaseFunction: (() => void) | null; } export interface BrowserPoolConfig { /** Minimum number of warm sessions to maintain (default: 1) */ minPoolSize: number; /** Maximum sessions allowed in pool (default: 5) */ maxPoolSize: number; /** Maximum session age in ms before refresh (default: 5 minutes) */ sessionMaxAge: number; /** Maximum idle time before session is recycled (default: 2 minutes) */ sessionIdleTimeout: number; /** Health check interval in ms (default: 30 seconds) */ healthCheckInterval: number; /** Pre-create sessions on initialization (default: true) */ warmupOnStart: boolean; /** Browser provider configuration */ provider?: Partial; /** Headless mode (default: true) */ headless: boolean; } export interface PoolStats { totalSessions: number; availableSessions: number; inUseSessions: number; healthySessions: number; unhealthySessions: number; totalUseCount: number; avgSessionAge: number; oldestSessionAge: number; } export declare class BrowserPool { private sessions; private config; private healthCheckTimer; private initialized; private shuttingDown; private playwrightModule; constructor(config?: Partial); /** * Initialize the pool and warm up sessions */ initialize(): Promise; /** * Create warm sessions to fill the pool */ warmup(count: number): Promise; /** * Create a new browser session */ private createSession; /** * Acquire a session from the pool * Returns an available healthy session, or creates a new one if needed */ acquire(): Promise; /** * Find an available healthy session */ private findAvailableSession; /** * Wait for a session to become available */ private waitForAvailableSession; /** * Check if a session has expired */ private isSessionExpired; /** * Release a session back to the pool */ release(sessionId: string): void; /** * Recycle a session (close old, create new if needed) */ private recycleSession; /** * Close a session and release resources */ private closeSession; /** * Run health checks on all sessions */ private runHealthChecks; /** * Check health of a single session */ private checkSessionHealth; /** * Get a new page from a session * Use this instead of session.context.newPage() to handle errors gracefully */ getPage(session: PooledSession): Promise; /** * Get pool statistics */ getStats(): PoolStats; /** * Shutdown the pool and close all sessions */ shutdown(): Promise; /** * Force refresh all sessions (useful for recovering from errors) */ forceRefreshAll(): Promise; /** * Check if pool is initialized and healthy */ isHealthy(): boolean; } /** * Get the default browser pool instance */ export declare function getDefaultPool(): BrowserPool; /** * Reset the default pool (for testing) */ export declare function resetDefaultPool(): Promise; //# sourceMappingURL=browser-pool.d.ts.map