import type { Browser, BrowserContext, BrowserContextOptions } from 'playwright'; import { type BrowserEngine } from './engines.js'; /** * One browser per process, held for as long as anything in it is using one. * * A run opens a collector world, a world per worker and a renderer, and each of * them used to launch a Chromium of its own: four launches for a run of three * workers, and four processes that share no cache. The process is the expensive * part — `docs/better-tests.md` measures a capture that launches a browser first * at about 205 ms against about 7.5 ms into an open page, some 27 captures — and * nothing a world or a renderer does needs a process to itself: each one owns * its pages and its contexts, and a browser only hosts them. * * So a browser is leased, not launched. The first lease launches it, every * later lease with the same launch options gets the same one, and the last * release closes it: whoever started it is whoever stops it, and that is the * lease count reaching zero. Launch options that differ get a browser of their * own, because a headed window or a different text setting paints different * pixels and must never be borrowed by a caller that asked for the other. * * A browser that dies is forgotten at once, so the next lease launches a new * one rather than handing out a corpse. */ /** A shared value and the one way to give it back. */ export interface Lease { readonly value: T; /** Give the value back. The last release closes it; a second call does nothing. */ release(): Promise; } /** How a browser is launched, and therefore which leases may share it. */ export interface Launch { readonly headless: boolean; readonly args: readonly string[]; } /** * The process's browser for this engine and these launch options, launched if * nothing holds one. */ export declare function leaseBrowser(engine: BrowserEngine, launch: Launch): Promise>; /** * A browser nobody else will be handed, closed by its release. * * For the reading that exists to rule the shared one out: `collectAlone` asks * whether a subject differs because something else ran first, and a browser * another world has used is something else. */ export declare function ownBrowser(engine: BrowserEngine, launch: Launch): Promise>; /** * The browser's context for these options, shared by every page opened with them. * * The context is where a browser keeps its HTTP cache, and an incognito context * starts empty: a page in a context of its own fetches and compiles everything * again. Pages that share one are answered by the first page's fetches. They * also share its cookies and storage, which is the price, and is why a caller * asks for this rather than getting it. */ export declare function leaseContext(browser: Browser, options: BrowserContextOptions): Promise>; /** A context of the caller's own, closed by its release. */ export declare function ownContext(browser: Browser, options: BrowserContextOptions): Promise>; //# sourceMappingURL=browsers.d.ts.map