October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PCOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk4 min

How to Start JavaScript Coverage in Puppeteer

Start Puppeteer JavaScript coverage before navigation or interaction, then stop the collection to inspect the scripts and ranges it captured.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start JavaScript coverage before the navigation or interaction you want to measure, then stop it to retrieve the collected script entries:

await page.coverage.startJSCoverage();
await page.goto('https://example.com');
// Exercise the routes and interactions you want to measure.
const jsCoverage = await page.coverage.stopJSCoverage();

The returned entries include script text and usage ranges. What they show depends on the pages and actions exercised during that collection.

Start coverage before the activity you want to measure

Create a page, start coverage, navigate, and exercise the relevant parts of the site. Stop coverage before leaving the page if you need to preserve that page’s results.

const page = await browser.newPage();

await page.coverage.startJSCoverage();
await page.goto('https://example.com');

// Exercise representative routes and interactions here.

const jsCoverage = await page.coverage.stopJSCoverage();

startJSCoverage() resolves when collection has started. stopJSCoverage() resolves with an array of JavaScript coverage entries. The official Puppeteer API example calculates a byte-use ratio from each entry’s script text and ranges:

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
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;
  }
}
console.log(`Bytes used: ${(usedBytes / totalBytes) * 100}%`);

This follows the calculation in the Puppeteer Coverage class documentation. Treat the result as a percentage of the scripts covered in this run, not as a universal measure of how much of the whole application is used. Include representative routes and interactions before using it to guide cleanup.

Choose coverage options deliberately

The Puppeteer JSCoverageOptions reference lists these defaults. It labels itself version 25.12.0; the Coverage class page is labeled version 25.10.0. These are documentation versions, not a guarantee that they match your installed package, so check the documentation for your pinned Puppeteer version when compatibility matters.

Option Documented default What it changes
resetOnNavigation true Coverage resets on navigation by default. Setting it to false does not guarantee prior-page data survives; Chrome may discard the previous page’s JavaScript execution environment.
reportAnonymousScripts false Includes anonymous scripts, such as dynamically created code from eval or new Function, when enabled. Puppeteer reports them under a debugger://VM URL unless the script includes a //# sourceURL comment.
includeRawScriptCoverage false Controls whether raw script coverage is included in the entries.
useBlockCoverage true Controls block-level versus function-level coverage collection.

Set options when starting collection if the defaults do not match what you need. For example, to include dynamically created anonymous scripts:

await page.coverage.startJSCoverage({ reportAnonymousScripts: true });

The Puppeteer API documentation notes that JavaScript Coverage does not include anonymous scripts by default.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Handle navigation as separate collections

Coverage can reset when a page navigates, and disabling resetOnNavigation is not a reliable way to retain all data: Chrome may discard the prior page’s execution environment and its coverage. For a multi-page test, stop coverage before navigating away, start a new collection on the next page, and merge the reports in your own reporting workflow.

Starting early matters when initial page execution is in scope. The Chrome DevTools Protocol’s Profiler reference cautions that JavaScript executed before precise coverage is enabled may be incomplete. It also notes that enabling precise coverage prevents optimized code and resets execution counters. Start collection before navigation rather than after the page has already loaded.

Use representative actions, not just a page load

Coverage records execution during the captured session. A page load alone will not exercise code behind menus, dialogs, tabs, forms, or later routes. Build the automation around the behaviors relevant to your question, and interpret unused ranges only in light of those actions.

  • For initial-load coverage, start before page.goto().
  • For interaction coverage, perform the interactions before calling stopJSCoverage().
  • For route-by-route results, collect each page separately when navigation could reset or discard data.

When to use Chrome DevTools instead

Use Puppeteer when you need a scripted, repeatable run that can be integrated into automation. For exploratory inspection, Chrome DevTools’ Coverage panel records JavaScript and CSS as you reload and interact with a page, and shows the analyzed resources and code usage. The Chrome DevTools Coverage guide describes unused-code inspection as a starting point; deciding whether to refactor depends on the application’s technology stack.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Troubleshoot incomplete or unexpected results

Coverage is empty or misses initial scripts

Check that startJSCoverage() completed before the navigation or script execution you intended to capture. The Chrome DevTools Protocol warns that code executed before precise coverage is enabled may be incomplete.

Anonymous scripts do not appear

Anonymous scripts are excluded by default. Start coverage with { reportAnonymousScripts: true } when dynamically created code matters. Such entries use a debugger://VM URL unless the script supplies a //# sourceURL comment.

Earlier pages are missing after navigation

Coverage resets on navigation by default, and setting resetOnNavigation: false cannot ensure Chrome retains a discarded execution environment. Stop coverage before leaving each page, start a fresh collection on the next page, and combine the resulting reports.

The percentage seems too high or too low

The calculation describes only the scripts and ranges captured in that run. Add the routes and interactions that represent actual use before treating the figure as evidence for code removal.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
Best Value
The SQL Programming Language: .
  • Used Book in Good Condition
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

If your goal is a website screenshot rather than JavaScript execution coverage, ScreenshotNeo can return a screenshot or PDF from one GET request. It does not collect Puppeteer coverage data; it is an alternative for capturing rendered pages without setting up browser automation.

ScreenshotNeo API documentation

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp
  • Cookie and consent banners are accepted before capture, and 60+ known consent platforms, newsletter popups, and chat widgets are removed; each step can be turned off.
  • Bot checks or CAPTCHAs, blank pages, timeouts, failed loads, and cache hits cost nothing; response headers identify the page verdict and whether the request was billed.
  • An MCP server provides take_screenshot, get_page_info, and capture_pdf tools for AI agents and MCP clients.
  • The Free plan includes 1,000 shots per month with no card; paid plans start at $5 for 3,000 shots. Every feature is available on every plan.

Sign up free for 1,000 screenshots a month, with no card required.

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.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. Shenzhen desk3 min
    HONOR Expands Beyond Smartphones With Humanoid Robot RevealHONOR said it unveiled its first humanoid robot at MWC 2026 and named shopping assistance, workplace inspections, and supportive companionship as intended uses. Later Robotics D1 claims and a reported…
  2. Cupertino desk5 min
    Apple Unveils AirPods Max 2: The Upgrade That Should Have Happened Years AgoAirPods Max 2 adds H2-powered audio features and Apple claims up to 1.5× more effective ANC, but its design, Smart Case, and 20-hour battery rating are unchanged. Wired lossless audio…
  3. Cupertino desk4 min
    Apple’s OLED Touch MacBooks Are Coming—but the Dynamic Island Is the Real GambleApple has not announced an OLED touchscreen MacBook, but reports point to high-end models arriving in late 2026 or early 2027. The reported Mac Dynamic Island could be useful, but…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.