import type { CDP } from ".."; import type { CDPSessionId } from "../types"; import type { SelectivityMapSourceMapUrlFn } from "../../../config/types"; /** * CDP "scriptId" is NOT stable across a test: it is reused for different scripts over time (a cross-process * navigation restarts the counter; bfcache restore re-issues the previous document's ids; freed ids get reassigned * to new scripts). "Profiler.takePreciseCoverage" reports only the raw "scriptId", with no way to tell which script * a given id currently means. Therefore coverage can only be attributed correctly if it is resolved WHILE the * scripts are still live and the "scriptId -> source" mapping is current. * * The orchestration in index.ts pauses the renderer at two boundaries and drives this class: * - on "beforeunload": takeCoverageSnapshot() — resolve the leaving page while its isolate is still alive * (required for cross-process navigation, where the old isolate is gone by the time the next document starts); * - at the new document start (and bfcache "pageshow"): flushPage() — resolve whatever is left of the previous * page (same-process, incl. code that ran during unload), then RESET precise coverage and CLEAR the script maps * so the next page parses into an empty map and its coverage window cannot mix with the previous page's. * Because the maps are cleared at every page boundary, plain "scriptId" keys are unambiguous within a page. */ export declare class JSSelectivity { private readonly _cdp; private readonly _sessionId; private readonly _sourceRoot; private readonly _mapSourceMapUrl; private _debuggerOnScriptParsedFn; private _scriptsSource; private _scriptsSourceMap; private _scriptIdToSourceUrl; private _scriptIdToSourceMapUrl; /** Last seen content hash per "scriptId" — used to detect a "scriptId" reused for a different script */ private _scriptIdToHash; /** Source files collected across all pages of the current test */ private readonly _dependingSourceFiles; constructor(cdp: CDP, sessionId: CDPSessionId, sourceRoot: string, mapSourceMapUrl: SelectivityMapSourceMapUrlFn | null); private _loadScriptSource; private _processScript; private _ensureScriptsAreLoading; private _waitForLoadingScripts; /** * Resolves the given coverage into original source files and accumulates them into "_dependingSourceFiles". * Must run while the "scriptId -> source" maps still describe the scripts the coverage was taken from * (i.e. before the page is navigated away and the maps are cleared). */ private _resolveCoverageToDeps; start(): Promise; /** * Called on "beforeunload", while the leaving page is still alive (its isolate not yet destroyed). Resolves the * page's coverage into dependencies. Does NOT reset coverage or clear maps — that happens later, at the next * page boundary (flushPage), once the leaving page has fully finished executing. */ takeCoverageSnapshot(): Promise; /** * Called at a page boundary — the new document's start, and on bfcache "pageshow" — while the renderer is paused * before the incoming page's scripts run. Resolves whatever is left of the previous page (same-process code that * ran during unload), then RESETS precise coverage and CLEARS the script maps. This guarantees the next page's * coverage window and "scriptId" namespace start empty, so reused ids cannot be mistaken for the previous page's. */ flushPage(): Promise; /** @param drop only performs cleanup without providing actual deps. Should be "true" if test is failed */ stop(drop?: boolean): Promise | null>; }