Start Puppeteer’s JavaScript coverage before the navigation or interaction you want to observe, exercise the page, then stop coverage and divide the executed script bytes by the total script bytes. The result is a byte-based measure of code observed during that browser session—not a test-pass rate or a measure of every path your application could take.
Collect and calculate JavaScript coverage
Puppeteer’s Coverage API returns script entries and the ranges observed as executed. This runnable example starts collection before navigation, leaves room for your test interactions, then calculates the used-byte percentage:
import puppeteer from 'puppeteer';
const browser = await puppeteer.launch();
try {
const page = await browser.newPage();
await page.coverage.startJSCoverage();
await page.goto('https://example.com');
// Exercise the interactions or flows whose code you want to measure here.
const entries = await page.coverage.stopJSCoverage();
let totalBytes = 0;
let usedBytes = 0;
for (const entry of entries) {
totalBytes += entry.text.length;
for (const range of entry.ranges) {
usedBytes += range.end - range.start - 1;
}
}
const percent = totalBytes === 0 ? 0 : (usedBytes / totalBytes) * 100;
console.log(`Bytes used: ${percent}%`);
} finally {
await browser.close();
}
Install Puppeteer in your project before running the script. Replace the example URL with your application and put the user actions under the navigation. The zero-total guard handles a session in which no script text is returned.
Choose what the coverage session includes
startJSCoverage() accepts options that affect which scripts and execution ranges appear in the report. The current API reference lists these defaults:
#1 Best Overall
| Option | Default | When to change it |
|---|---|---|
resetOnNavigation |
true |
Navigation resets coverage by default. For a journey spanning pages, stop and restart collection per page, then merge the reports downstream rather than relying on this option being false. |
reportAnonymousScripts |
false |
Set to true if dynamically generated scripts such as eval or new Function matter. They are named with debugger://VM-style URLs unless a //# sourceURL comment supplies a URL. |
useBlockCoverage |
true |
Set to false to request function-level rather than block-level coverage. |
includeRawScriptCoverage |
false |
Enable only when a downstream workflow needs V8’s raw script coverage entries. |
These defaults are documented in Puppeteer’s startJSCoverage options reference. The options reference is versioned; check it against the Puppeteer release installed in your project.
Handle navigation without losing the report
Coverage collection brackets runtime activity. If you need results from multiple pages, stop coverage before leaving the current page, start a new collection on the next page, and merge the returned reports in your reporting workflow. Puppeteer warns that setting resetOnNavigation to false does not guarantee coverage survives navigation, because Chrome may discard the previous page’s execution environment. See the JSCoverageOptions interface.
Rank #2
Interpret the percentage carefully
The example totals each entry’s script text and adds the lengths of its executed ranges, then calculates usedBytes / totalBytes × 100. It measures observed execution against script text in the collected session. It does not report what fraction of tests passed, how many branches were specified, or how much of all theoretically reachable application code was exercised.
A low percentage can indicate that the scenarios did not exercise much code, but the number alone cannot tell whether uncovered code is dead, intentionally conditional, or simply outside the tested route. Treat it as a signal to investigate alongside the flows your tests cover, not as a stand-alone quality score.
Windows Errors? Fix Them Before They Spread
Repair common Windows errors and clear accumulated junk for a smoother, more stable PC - no reinstall needed.Free scan · no reinstallOutdated Drivers Are Slowing You Down
One free scan finds every outdated or missing driver and matches the right update for your exact hardware.Free scan · exact hardware matchTroubleshoot common coverage gaps
- No entries or a zero total: Confirm that collection starts before the page activity and that scripts load during the session. The example returns zero rather than dividing by zero if no script text is collected.
- Coverage disappears after a page change: Navigation resets coverage by default, and disabling the reset does not ensure the old execution environment remains available. Stop before navigation and start a fresh collection on the next page.
- Generated scripts are missing: Anonymous scripts are excluded by default. Start coverage with
reportAnonymousScripts: trueif those scripts are in scope. - The report is too coarse for the question: Block-level ranges are the default. Set
useBlockCoverage: falsewhen function-level data is more appropriate. - A reporting tool cannot consume Puppeteer’s entries: Puppeteer’s guide points to puppeteer-to-istanbul to convert the output into a format consumable by Istanbul.
Capture a screenshot without managing Puppeteer
For a screenshot rather than a JavaScript coverage report, ScreenshotNeo offers a one-request screenshot API. This does not replace Puppeteer’s coverage collection; it is an option when the task is capturing a page image or PDF.
Or skip the browser setup
Make one GET request for a screenshot (replace the URL with the page you need):
Rank #4
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Before capture, it accepts cookie or consent banners as a visitor and removes 60+ known consent platforms, newsletter popups and chat widgets; each step can be turned off. Bot checks, blank pages, timeouts, failed loads and cache hits are not billed, and response headers identify the page verdict and billing status. An MCP server provides take_screenshot, get_page_info and capture_pdf tools for AI agents. The free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots.
Sign up for ScreenshotNeo’s free plan to try it without a card.
Quick Recap
Best Value
Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.




