Coverage
Coverage gathers information about parts of JavaScript and CSS that were used by the page.
An example of using JavaScript coverage to produce Istanbul report for page load:
noteCoverage APIs are only supported on Chromium-based browsers.
const { chromium } = require('playwright');
const v8toIstanbul = require('v8-to-istanbul');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.coverage.startJSCoverage();
await page.goto('https://chromium.org');
const coverage = await page.coverage.stopJSCoverage();
for (const entry of coverage) {
const converter = v8toIstanbul('', 0, { source: entry.source });
await converter.load();
converter.applyCoverage(entry.functions);
console.log(JSON.stringify(converter.toIstanbul()));
}
await browser.close();
})(); Methods
startCSSCoverage
Returns coverage is started
Usage
await coverage.startCSSCoverage(); await coverage.startCSSCoverage(options);
Arguments
-
optionsObject (optional)-
resetOnNavigationboolean (optional)Whether to reset coverage on every navigation. Defaults to
true.
-
Returns
startJSCoverage
Returns coverage is started
noteAnonymous scripts are ones that don't have an associated url. These are scripts that are dynamically created on the page using
evalornew Function. If reportAnonymousScripts is set totrue, anonymous scripts will have__playwright_evaluation_script__as their URL.
Usage
await coverage.startJSCoverage(); await coverage.startJSCoverage(options);
Arguments
-
optionsObject (optional)-
reportAnonymousScriptsboolean (optional)Whether anonymous scripts generated by the page should be reported. Defaults to
false. -
resetOnNavigationboolean (optional)DiscouragedSettings this to
falsemay still reset on navigations.Whether to reset coverage on every navigation. Defaults to
true. Note that passingfalsedoes not guarantee that coverage persists through navigations, due to browser architecture limitations.
-
Returns
stopCSSCoverage
Returns the array of coverage reports for all stylesheets
noteCSS Coverage doesn't include dynamically injected style tags without sourceURLs.
Usage
await coverage.stopCSSCoverage();
Returns
stopJSCoverage
Returns the array of coverage reports for all scripts
noteJavaScript Coverage doesn't include anonymous scripts by default. However, scripts with sourceURLs are reported.
Usage
await coverage.stopJSCoverage();
Returns
© 2026 Microsoft
Licensed under the Apache License, Version 2.0.
https://playwright.dev/docs/api/class-coverage