/** * Browser Manager - Handles Playwright browser lifecycle * * Playwright is OPTIONAL - the module gracefully degrades if not installed. * Check isPlaywrightAvailable() before using browser functionality. * * Supports multiple browser providers: * - Local: Uses installed Playwright (default) * - Browserless.io: Set BROWSERLESS_TOKEN env var * - Bright Data: Set BRIGHTDATA_AUTH env var (best for anti-bot) * - Custom: Set BROWSER_ENDPOINT env var */ import type { BrowserContext, Page } from 'playwright'; import type { NetworkRequest, ConsoleMessage, WebSocketConnection } from '../types/index.js'; import { type BrowserProvider, type BrowserProviderType, type BrowserProviderConfig } from './browser-providers.js'; export type { Page } from 'playwright'; export interface BrowserConfig { headless?: boolean; screenshotDir?: string; slowMo?: number; devtools?: boolean; provider?: Partial; } export declare class BrowserManager { private browser; private contexts; private config; private provider; private slotReleaseFunction; private sessionId; constructor(config?: Partial); /** * Check if Playwright is available without loading it */ static isPlaywrightAvailable(): boolean; /** * Get the Playwright load error if any */ static getPlaywrightError(): string | null; /** * Update configuration at runtime */ setConfig(config: Partial): void; /** * Enable visual debugging mode (non-headless with devtools) */ enableDebugMode(): void; /** * Disable visual debugging mode (return to headless) */ disableDebugMode(): void; /** * Ensure Playwright is available, throwing a helpful error if not */ private ensurePlaywright; /** * Attach lifecycle handlers so a disconnected/closed browser or context * drops its cached reference. Without this, remote providers like * Browserless (which enforce max session durations) leave a stale truthy * `this.browser` that passes the `!this.browser` guard in initialize(), * causing "Target page, context or browser has been closed" on the * first request after the server-side session expires. */ private wireBrowserDisconnect; initialize(): Promise; /** * Check if using a remote browser provider */ isUsingRemoteBrowser(): boolean; /** * Get the current browser provider */ getProvider(): BrowserProvider; /** * Get information about all available providers */ static getAvailableProviders(): { type: BrowserProviderType; name: string; configured: boolean; capabilities: import("./browser-providers.js").ProviderCapabilities; envVars: string[]; }[]; getContext(profile?: string): Promise; browse(url: string, options?: { captureNetwork?: boolean; captureConsole?: boolean; captureWebSockets?: boolean; waitFor?: 'load' | 'domcontentloaded' | 'networkidle'; timeout?: number; profile?: string; }): Promise<{ page: Page; network: NetworkRequest[]; console: ConsoleMessage[]; websockets: WebSocketConnection[]; }>; cleanup(): Promise; /** * Get usage stats from the provider (if rate-limited) */ getUsageStats(): { unitsUsed: number; unitsRemaining: number; activeConnections: number; } | null; /** * Take a screenshot of the current page */ screenshot(page: Page, options?: { name?: string; fullPage?: boolean; element?: string; }): Promise; /** * Take a screenshot and return as base64 */ screenshotBase64(page: Page, options?: { fullPage?: boolean; element?: string; }): Promise; /** * Browse and capture screenshots at key points */ browseWithScreenshots(url: string, options?: { captureOnLoad?: boolean; captureOnError?: boolean; prefix?: string; profile?: string; }): Promise<{ page: Page; screenshots: string[]; network: NetworkRequest[]; console: ConsoleMessage[]; }>; /** * Get current configuration */ getConfig(): BrowserConfig; } //# sourceMappingURL=browser-manager.d.ts.map