import type { EventEmitter } from 'node:events'; export interface ConsoleMessage { type(): string; text(): string; location(): { url: string }; } export interface Route { request(): { url(): string; method(): string; headers(): Record; resourceType(): string; postDataBuffer(): Buffer | null }; fulfill( response: { status?: number; body?: string | Buffer; contentType?: string; headers?: Record } ): Promise; continue(): Promise; abort( reason?: string ): Promise; } interface Bounds { x: number; y: number; width: number; height: number } interface Frame { url(): string; parentFrame(): null } interface ScreenshotOptions { path?: string; type?: 'png'; timeout?: number; clip?: Bounds; omitBackground?: boolean } interface NavigationOptions { timeout?: number; waitUntil?: string } interface ContextOptions { gpu?: boolean; viewport?: { width: number; height: number }; deviceScaleFactor?: number; /** Zero runs as fast as possible; use a display interval for pacing benchmarks. */ frameIntervalMs?: number; recordVideo?: { dir: string; size?: { width: number; height: number } }; } /** Native canvas rendering, Yoga layout, and Skia text measurement. */ export interface RendererLocator { screenshot( options?: ScreenshotOptions ): Promise; evaluateAll( callback: ( elements: Element[], arg: A ) => R | Promise, arg?: A ): Promise; boundingBox(): Promise; nth( index: number ): RendererLocator; first(): RendererLocator; } export interface RendererPage extends EventEmitter<{ console: [ ConsoleMessage ]; pageerror: [ Error ]; unhandledrejection: [ string ]; crash: []; close: []; framenavigated: [ Frame ]; }> { evaluate( callback: () => R | Promise ): Promise; evaluate( callback: ( arg: A ) => R | Promise, arg: A ): Promise; waitForFunction( callback: string | ( ( arg: A ) => unknown ), arg?: A, options?: { timeout?: number; polling?: number | 'raf' } ): Promise; goto( url: string, options?: NavigationOptions ): Promise; reload( options?: NavigationOptions ): Promise; screenshot( options?: ScreenshotOptions ): Promise; close(): Promise; waitForTimeout( ms: number ): Promise; waitForLoadState( state?: string, options?: { timeout?: number } ): Promise; mainFrame(): Frame; url(): string; waitForURL( expected: string | RegExp | ( ( url: URL ) => boolean ), options?: { timeout?: number } ): Promise; isClosed(): boolean; context(): RendererContext; locator( selector: string ): RendererLocator; } export interface RendererContext { /** `workers: true` also runs the script in every worker thread, which browsers never do. */ addInitScript( script: string | { content: string; workers?: boolean } | ( ( arg: A ) => unknown ), arg?: A ): Promise; route( pattern: string, handler: ( route: Route ) => unknown ): Promise; close(): Promise; browser(): RendererBrowser; newPage(): Promise; } export interface RendererBrowser extends EventEmitter<{ disconnected: [] }> { readonly execution: 'node'; gpuInfo(): Promise<{ execution: 'node'; vendor: string; architecture: string; device: string; description: string; isFallbackAdapter: boolean }>; newContext( options?: ContextOptions ): Promise; newPage( options?: ContextOptions ): Promise; isConnected(): boolean; version(): string; close(): Promise; } export function launchNodeRenderer(): Promise;