Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Microsoft Playwright CrCoverage

From Leeroopedia
Knowledge Sources
Domains Chromium, Coverage
Last Updated 2026-02-12 00:00 GMT

Overview

Concrete tool for collecting JavaScript and CSS code coverage data from Chromium browsers provided by the Playwright library.

Description

The `CRCoverage` class coordinates JavaScript and CSS coverage collection through two internal classes: `JSCoverage` and `CSSCoverage`. `JSCoverage` uses CDP's `Profiler` and `Debugger` domains to track script execution, collecting precise coverage ranges with optional per-block granularity and script content reset. `CSSCoverage` uses the `CSS` and `DOM` domains to track stylesheet usage. Both support start/stop lifecycle with proper cleanup. The `CRCoverage` facade exposes `startJSCoverage`/`stopJSCoverage` and `startCSSCoverage`/`stopCSSCoverage` methods that race against a `Progress` tracker for cancellation support.

Usage

Use CrCoverage when collecting code coverage metrics from Chromium pages via `page.coverage.startJSCoverage()` and related APIs.

Code Reference

Source Location

Signature

export class CRCoverage {
  constructor(client: CRSession);
  async startJSCoverage(progress: Progress, options: channels.PageStartJSCoverageParams): Promise<void>;
  async stopJSCoverage(): Promise<channels.PageStopJSCoverageResult>;
  async startCSSCoverage(progress: Progress, options: channels.PageStartCSSCoverageParams): Promise<void>;
  async stopCSSCoverage(): Promise<channels.PageStopCSSCoverageResult>;
}

Import

import { CRCoverage } from '../server/chromium/crCoverage';

I/O Contract

Inputs

Name Type Required Description
client CRSession Yes CDP session for the target page
progress Progress Yes Progress tracker for cancellation
options PageStartJSCoverageParams / PageStartCSSCoverageParams Yes Coverage options (resetOnNavigation, reportAnonymousScripts)

Outputs

Name Type Description
jsCoverage PageStopJSCoverageResult Array of JS coverage entries with URL, source, and ranges
cssCoverage PageStopCSSCoverageResult Array of CSS coverage entries with URL, source, and ranges

Usage Examples

import { CRCoverage } from '../server/chromium/crCoverage';

const coverage = new CRCoverage(crSession);
await coverage.startJSCoverage(progress, { resetOnNavigation: true });
// ... navigate and interact ...
const jsCoverage = await coverage.stopJSCoverage();
for (const entry of jsCoverage.entries) {
  console.log(`${entry.url}: ${entry.ranges.length} ranges`);
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment