import { Coverage } from "https://deno.land/x/pptr@1.2.0/src/Coverage.ts";
The Coverage class provides methods to gathers information about parts of JavaScript and CSS that were used by the page.
Examples
An example of using JavaScript and CSS coverage to get percentage of initially
executed code:
An example of using JavaScript and CSS coverage to get percentage of initially executed code:
// Enable both JavaScript and CSS coverage
await Promise.all([
page.coverage.startJSCoverage(),
page.coverage.startCSSCoverage()
]);
// Navigate to page
await page.goto('https://example.com');
// Disable both JavaScript and CSS coverage
const [jsCoverage, cssCoverage] = await Promise.all([
page.coverage.stopJSCoverage(),
page.coverage.stopCSSCoverage(),
]);
let totalBytes = 0;
let usedBytes = 0;
const coverage = [...tsCoverage, ...cssCoverage];
for (const entry of coverage) {
totalBytes += entry.text.length;
for (const range of entry.ranges)
usedBytes += range.end - range.start - 1;
}
console.log(`Bytes used: ${usedBytes / totalBytes * 100}%`);
Constructors
new
Coverage(client: CDPSession)Methods
startCSSCoverage(options?: CSSCoverageOptions): Promise<void>
startJSCoverage(options?: JSCoverageOptions): Promise<void>
stopCSSCoverage(): Promise<CoverageEntry[]>
stopJSCoverage(): Promise<CoverageEntry[]>