import { EventEmitter } from 'eventemitter3'; import { BrowserInstance, BrowserPoolConfig, Logger } from './types'; /** * @file Implements a pool for managing Playwright browser instances. * This helps in reusing browser instances to improve performance and control resource usage * by limiting the maximum number of concurrent browsers. */ /** * Manages a pool of Playwright browser instances. * This class handles the creation, acquisition, release, and cleanup of browser instances, * ensuring efficient reuse and adherence to configured limits (e.g., max size, instance age). * It emits events related to pool operations like 'pool:acquire', 'pool:release', 'pool:cleanup'. * @extends EventEmitter */ export declare class BrowserPool extends EventEmitter { private pool; private config; private logger; private cleanupTimer?; private isShuttingDown; /** * Creates an instance of BrowserPool. * @param config The configuration object for the browser pool. See {@link BrowserPoolConfig}. * @param logger An instance of a logger conforming to the {@link Logger} interface. */ constructor(config: BrowserPoolConfig, logger: Logger); /** * Acquires a browser instance from the pool. * If an idle instance is available, it's reused. * If the pool is not full, a new instance is created. * If the pool is full and no instances are idle, it waits for one to become available. * Emits 'pool:acquire' event when an instance is acquired. * @returns A Promise that resolves to an available {@link BrowserInstance}. * @throws Error if the pool is shutting down or if waiting for an instance times out. */ acquire(): Promise; /** * Releases a previously acquired browser instance back to the pool, * marking it as available for reuse. * Emits 'pool:release' event. * @param instance The {@link BrowserInstance} to release. */ release(instance: BrowserInstance): void; /** * Retrieves statistics about the current state of the browser pool. * @returns An object containing: * - `total`: The total number of browser instances currently managed by the pool (both active and idle). * - `inUse`: The number of browser instances currently acquired and in use. * - `available`: The number of idle browser instances available for immediate acquisition. * - `maxSize`: The maximum number of browser instances the pool is configured to allow. */ getStats(): { total: number; inUse: number; available: number; maxSize: number; }; /** * Periodically cleans up old and unused browser instances from the pool. * An instance is considered old if it has not been used for a duration exceeding * `config.maxAge` and is not currently in use. * This method is typically called by an internal timer. * Emits 'pool:cleanup' event with the number of removed instances. * @returns A Promise that resolves when the cleanup operation is complete. */ cleanupOldInstances(): Promise; /** * Shuts down the browser pool. * This process involves stopping the cleanup timer and closing all active browser instances * managed by the pool. No new instances can be acquired after shutdown is initiated. * @returns A Promise that resolves when all browser instances have been closed and resources are freed. */ shutdown(): Promise; /** * Create a new browser instance */ private createInstance; /** * Destroy a browser instance */ private destroyInstance; /** * Wait for an available instance */ private waitForAvailableInstance; /** * Start the cleanup timer */ private startCleanupTimer; } /** * Provides a default configuration for the {@link BrowserPool}. * This configuration can be used as a base and customized as needed. * Key defaults include: * - `maxSize`: 5 browser instances. * - `maxAge`: 30 minutes for an instance before it's recycled. * - `headless`: True (or as per `BROWSER_HEADLESS` env var). * - `cleanupInterval`: 5 minutes. */ export declare const defaultBrowserPoolConfig: BrowserPoolConfig; //# sourceMappingURL=browser-pool.d.ts.map