import { EventEmitter } from 'node:events'; import type { Compiler } from '@rspack/core'; import { type ReloadBroker, type ReloadInstruction } from '../plugin-reload/index.js'; import type { BrowserType } from '../types.js'; export declare const BROWSER_LAUNCH_TIMEOUT_MS: number; export declare const BROWSER_REQUEST_TIMEOUT_MS = 60000; export interface CompiledEvent { outputPath: string; contextDir: string; isFirstCompile: boolean; reloadInstruction?: ReloadInstruction; extensionsToLoad?: string[]; } export interface BuildErrorEvent { errors: string[]; /** The launcher's error code on a launch failure, such as `E_BROWSER_START_TIMEOUT`. */ code?: string; } export interface BuildEventMap { compiled: [CompiledEvent]; error: [BuildErrorEvent]; } export declare class BuildEmitter extends EventEmitter { constructor(); } export declare function reportLaunchFailure(emitter: BuildEmitter, failure: { browser: BrowserType; error: unknown; }): void; export interface BrowserLaunchOptions { browser: BrowserType; outputPath: string; contextDir: string; extensionsToLoad: string[]; mode?: 'development' | 'production'; enableDevtools?: boolean; noOpen?: boolean; profile?: string | false; profileSource?: 'flag' | 'config'; persistProfile?: boolean; keepProfileChanges?: boolean; copyFromProfile?: string; preferences?: Record; browserFlags?: string[]; excludeBrowserFlags?: string[]; startingUrl?: string; chromiumBinary?: string; geckoBinary?: string; instanceId?: string; port?: number | string; dryRun?: boolean; logLevel?: string; logContexts?: string[]; logFormat?: 'pretty' | 'json' | 'ndjson'; logTimestamps?: boolean; logColor?: boolean; logUrl?: string; logTab?: number | string; emulatorViewerUrl?: string; logSink?: BrowserLogSink; awaitBootRegistrations?: (timeoutMs: number) => Promise<'settled' | 'timeout'>; } /** Browser-generated log entry normalized by the launcher's CDP controller. */ export interface BrowserLogSinkEvent { level: 'log' | 'info' | 'warn' | 'error' | 'debug'; text: string; source?: string; url?: string; lineNumber?: number; timestamp?: number; } type BrowserLogSink = (event: BrowserLogSinkEvent) => void; export type RestartHold = (compiler: object, compilation?: object) => boolean; export interface ExtensionLoadRetryResult { status: 'loaded' | 'refused' | 'unknown'; reason?: string; extensionId?: string; } export interface BrowserController { enableUnifiedLogging(opts: { level?: string; contexts?: string[]; format?: 'pretty' | 'json' | 'ndjson'; timestamps?: boolean; color?: boolean; urlFilter?: string; tabFilter?: number | string; }): Promise; /** The browser's refusal reason for this session, or null when it loaded. */ getExtensionLoadRefusal?(): string | null; /** Re-offer the current dist. Only ever called while the session is refused. */ retryExtensionLoad?(): Promise; /** Start a suspended background again. Firefox only. */ wakeBackground?(): Promise; } export type BrowserLauncherFn = (opts: BrowserLaunchOptions) => Promise; export interface RunnerPlugin { readonly emitter: BuildEmitter; extensionsToLoad: string[]; apply(compiler: Compiler): void; setLaunchSettledListener?(listener: () => void): void; } interface BrowsersPluginOptions { /** Injected browser launcher, provided by the CLI from programs/extension/browsers/ */ launcher: BrowserLauncherFn; /** Browser-related options forwarded to the launcher (outputPath/contextDir/extensionsToLoad are filled at compile time) */ browserOptions: Omit; } /** * BrowsersPlugin * * An rspack plugin that manages the browser lifecycle for extension development. * On first successful compilation it launches a browser via the injected launcher * function. On later ones it asks plugin-reload what the edit must reload and, * once the browser is up with the extension loaded, has it sent. * * A `BuildEmitter` is exposed as `plugin.emitter`, which extensionDev returns, * so a programmatic caller can subscribe to build events without rspack. */ export declare class BrowsersPlugin implements RunnerPlugin { private readonly options; static readonly name = "plugin-browsers"; /** EventEmitter for build lifecycle events (compiled, error). */ readonly emitter: BuildEmitter; /** * Every unpacked folder the browser loads, the user's dist and companions. * rspack-config.ts sets it before the first compile. */ extensionsToLoad: string[]; private isFirstCompile; private launchStillRunning; private launchHeld; private controller; private logSink; private emulatorViewerUrl; private instanceId; private readyListener; private launchSettledListener; private lastReportedRefusal; private lastRetryFailure; private retryStillRunning; private lastBuild; private readonly reloads; constructor(options: BrowsersPluginOptions); /** * The dev server injects the control-bridge broker so a launched * Chromium reloads through the SW producer (the same path as `--no-browser`), * not the CDP controller. Called once, before the first compile. */ setReloadBroker(broker: ReloadBroker): void; setRestartHold(isHeld: RestartHold): void; setLogSink(sink: BrowserLogSink): void; private bootRegistrationsHold; setEmulatorViewerUrl(url: string): void; setInstanceId(instanceId: string): void; setReadyListener(listener: () => void): void; setLaunchSettledListener(listener: () => void): void; private announceLaunchSettled; private announceReady; private launchBrowser; private launchNoLongerHeld; private emitCompiled; private enableBrowserLogs; wakeBackground(): Promise; private warnRetryFailed; private retryAnswered; private extensionLoadedOnRetry; private retryRefusedExtensionLoad; apply(compiler: Compiler): void; } export {};