The Tool Desk
Outbyte PC Repair FREEClear out junk files and repair common Windows errorsFree Scan →Outbyte Driver Updater FREEScan for outdated or missing drivers - takes under a minuteDriver Scan →Use Puppeteer’s page.coverage.startJSCoverage() before the page activity you want to measure, then call page.coverage.stopJSCoverage() afterward. The returned entries contain script text and ranges recorded as executed. For coverage spanning navigations, stop and restart collection at each transition; setting resetOnNavigation: false does not guarantee that earlier data survives.
Collect JavaScript coverage on a page
Coverage is exposed on a Puppeteer Page. Start it before navigating or triggering the behavior under test, and stop it when that behavior is finished. This runnable example visits a page, collects coverage, and calculates the share of collected script bytes represented by recorded used ranges.
const jsCoverage = await page.coverage.startJSCoverage();
await page.goto('https://example.com');
const jsCoverage = await page.coverage.stopJSCoverage();
The first line above should not assign a value: startJSCoverage() starts collection, while stopJSCoverage() returns the entries. Use this corrected complete sequence:
await page.coverage.startJSCoverage();
await page.goto('https://example.com');
const jsCoverage = await page.coverage.stopJSCoverage();
let totalBytes = 0;
let usedBytes = 0;
for (const entry of jsCoverage) {
totalBytes += entry.text.length;
for (const range of entry.ranges) {
usedBytes += range.end - range.start - 1;
}
}
const percentUsed = totalBytes === 0 ? 0 : (usedBytes / totalBytes) * 100;
console.log(`Used script bytes: ${percentUsed.toFixed(2)}%`);
The byte calculation follows Puppeteer’s documented example. Interpret the result as the percentage of collected script text represented by recorded used ranges—not as proof that tests are complete or that the code is well tested. See the Puppeteer Coverage class documentation and the stopJSCoverage() method reference.
#1 Best Overall
Measure interactions, not just initial loading
Place the start call before the actions whose scripts you want represented. For example, start coverage, navigate, click or otherwise exercise the relevant controls, then stop coverage. If collection starts after an interaction, that interaction’s earlier execution is not part of the collection.
Choose coverage options
startJSCoverage() accepts options that affect what is recorded. The documented defaults are shown below; consult the startJSCoverage() reference for the API signature and JSCoverageOptions for option details.
Rank #2
| Option | Documented default | Effect |
|---|---|---|
resetOnNavigation |
true |
Resets collection on navigation. A value of false is not a guarantee that data from the previous page survives. |
reportAnonymousScripts |
false |
Includes scripts without an associated URL, such as code created with eval or new Function. Such scripts generally use a debugger://VM URL unless a //# sourceURL comment supplies one. |
includeRawScriptCoverage |
false |
Includes raw V8 script coverage entries in the result. Turn it on when a downstream consumer needs that raw data. |
useBlockCoverage |
true |
Collects block-level rather than function-level coverage. |
For example, to include anonymous scripts and request function-level collection:
await page.coverage.startJSCoverage({
reportAnonymousScripts: true,
useBlockCoverage: false,
includeRawScriptCoverage: false,
resetOnNavigation: true,
});
Set options deliberately: adding anonymous or raw data may change what downstream tools receive, and consumers must be able to handle the resulting entries.
Handle page navigations reliably
Do not rely on resetOnNavigation: false to preserve coverage across page transitions. Chrome may discard the previous page’s JavaScript execution environment and its coverage data. Puppeteer documents this caveat in the JSCoverageOptions reference.
For a multi-page journey, collect each page separately and combine the reports in your own reporting step:
Rank #4
- Start coverage before the activity on the first page.
- Stop coverage before navigating away and save the returned entries.
- Navigate to the next page, start a fresh collection, and exercise that page.
- Stop and save that collection; repeat for each transition.
- Merge the saved reports in the downstream workflow.
This makes each page’s collection boundary explicit rather than assuming browser execution data will persist across navigation.
Send the result to Istanbul
Puppeteer’s Coverage documentation points to puppeteer-to-istanbul as a route for producing output consumable by Istanbul. The Puppeteer reference identifies that converter but does not prescribe a universal Istanbul configuration or pipeline, so configure the conversion for your project’s reporting setup.
What’s actually slowing this PC down?
Pick the symptom - the matching free tool is one click away.
Best Value
Troubleshoot missing or unexpected coverage
- No useful entries: Verify that coverage starts before navigation or the code path under test, and that it stops after the relevant activity.
- Coverage appears to vanish after navigation: Chrome may discard the prior page’s execution environment. Stop before navigating, start a new collection afterward, and merge the resulting reports.
- Dynamic scripts are absent: Enable
reportAnonymousScriptsif you need scripts without associated URLs, includingevalornew Functioncode. - Granularity does not match your report: Check
useBlockCoverage; its documented default is block-level coverage, whilefalserequests function-level coverage. - A downstream consumer lacks raw entries: Set
includeRawScriptCoverage: trueonly if that consumer needs raw V8 data. - The percentage is zero or misleading: Check whether entries were collected and avoid dividing by zero when total script text is empty. The percentage describes recorded used bytes, not test completeness.
Or skip the browser setup
ScreenshotNeo captures screenshots or PDFs; it does not collect Puppeteer JavaScript coverage. If the task is to capture a page rather than measure executed code, its one-request API is an alternative:
Quick Recap
curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
See the ScreenshotNeo API documentation for request options. Cookie banners, popups, and chat widgets are removed before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots. The free plan includes 1,000 screenshots a month with no card, and paid plans start at $5 for 3,000. Learn about ScreenshotNeo, or sign up for 1,000 free screenshots a month with no card.
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.




