@dorothywebb/any-browser-mcp
Version:
Any Browser MCP - Launch Chrome with your actual data in debug mode for comprehensive browser automation
163 lines • 4.65 kB
TypeScript
/**
* Connection Pool for Browser Connections
*
* @fileoverview Manages a pool of browser connections to improve performance
* with multiple concurrent operations. Provides connection reuse, automatic
* cleanup, and resource management.
*
* @example
* ```typescript
* import { ConnectionPool } from './ConnectionPool.js';
*
* const pool = new ConnectionPool({ maxConnections: 5 });
*
* // Get a connection from the pool
* const connection = await pool.acquire();
*
* try {
* // Use the connection
* await connection.sendCommand('Page.navigate', { url: 'https://example.com' });
* } finally {
* // Return connection to pool
* pool.release(connection);
* }
* ```
*
* @category Utilities
*/
import { BrowserConnection } from './BrowserConnection.js';
/**
* Configuration options for the connection pool.
*/
export interface ConnectionPoolOptions {
/** Maximum number of connections in the pool */
maxConnections?: number;
/** Minimum number of connections to maintain */
minConnections?: number;
/** Maximum time a connection can be idle before being closed (ms) */
maxIdleTime?: number;
/** Interval for cleaning up idle connections (ms) */
cleanupInterval?: number;
/** Maximum time to wait for a connection (ms) */
acquireTimeout?: number;
/** Enable verbose logging */
verbose?: boolean;
}
/**
* Statistics about the connection pool.
*/
export interface PoolStats {
/** Total connections in the pool */
totalConnections: number;
/** Connections currently in use */
activeConnections: number;
/** Connections available for use */
availableConnections: number;
/** Number of times connections were acquired */
acquisitions: number;
/** Number of times connections were released */
releases: number;
/** Number of connections created */
connectionsCreated: number;
/** Number of connections destroyed */
connectionsDestroyed: number;
/** Average connection age in milliseconds */
averageConnectionAge: number;
}
/**
* Connection pool for managing browser connections efficiently.
*
* @description This class implements a connection pool pattern to reuse
* browser connections across multiple operations, reducing the overhead
* of creating new connections for each request.
*/
export declare class ConnectionPool {
private connections;
private waitingQueue;
private options;
private cleanupTimer?;
private stats;
private config;
/**
* Creates a new connection pool.
*
* @param options - Configuration options for the pool
*/
constructor(options?: ConnectionPoolOptions);
/**
* Acquires a connection from the pool.
*
* @returns Promise that resolves to a browser connection
* @throws Error if unable to acquire connection within timeout
*
* @example
* ```typescript
* const connection = await pool.acquire();
* try {
* await connection.sendCommand('Page.navigate', { url: 'https://example.com' });
* } finally {
* pool.release(connection);
* }
* ```
*/
acquire(): Promise<BrowserConnection>;
/**
* Releases a connection back to the pool.
*
* @param connection - The connection to release
*
* @example
* ```typescript
* pool.release(connection);
* ```
*/
release(connection: BrowserConnection): void;
/**
* Gets current pool statistics.
*
* @returns Current pool statistics
*/
getStats(): PoolStats;
/**
* Closes all connections and shuts down the pool.
*
* @example
* ```typescript
* await pool.shutdown();
* ```
*/
shutdown(): Promise<void>;
/**
* Finds an available connection in the pool.
*/
private findAvailableConnection;
/**
* Finds a pooled connection by its browser connection instance.
*/
private findPooledConnection;
/**
* Creates a new connection and adds it to the pool.
*/
private createConnection;
/**
* Waits for a connection to become available.
*/
private waitForConnection;
/**
* Processes the waiting queue when connections become available.
*/
private processWaitingQueue;
/**
* Starts the cleanup timer for idle connections.
*/
private startCleanupTimer;
/**
* Cleans up idle connections that exceed the maximum idle time.
*/
private cleanupIdleConnections;
/**
* Updates the pool statistics.
*/
private updateStats;
}
//# sourceMappingURL=ConnectionPool.d.ts.map