DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
World desk4 min

How to Configure JavaScript Coverage in Puppeteer

Start Puppeteer coverage before navigation or interactions, choose the right collection options, and stop and restart around document changes to avoid losing data.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start JavaScript coverage before the page activity you want to measure, then stop it to retrieve script entries and their executed ranges. In Puppeteer, use page.coverage.startJSCoverage() and page.coverage.stopJSCoverage(). For coverage across documents, stop and restart around navigation; setting resetOnNavigation: false does not guarantee Chrome will retain the previous document’s data.

How to get JavaScript coverage in Puppeteer

The Coverage object belongs to a Puppeteer Page. Start collection before navigation or interactions, perform the work being measured, and stop collection to receive an array of JavaScript entries.

import puppeteer from 'puppeteer';

const browser = await puppeteer.launch();
try {
  const page = await browser.newPage();

  await page.coverage.startJSCoverage({
    resetOnNavigation: true,
    reportAnonymousScripts: false,
    includeRawScriptCoverage: false,
    useBlockCoverage: true,
  });

  await page.goto('https://example.com');
  // Perform the interactions whose execution should be included.

  const entries = await page.coverage.stopJSCoverage();
  console.log(`Collected coverage for ${entries.length} scripts`);
  // Process entries or pass them to an Istanbul conversion tool.
} finally {
  await browser.close();
}

The four explicit values above are the documented defaults in Puppeteer’s 25.10.0 startJSCoverage() reference. A minimal setup can omit the options object:

await page.coverage.startJSCoverage();
await page.goto('https://example.com');
const entries = await page.coverage.stopJSCoverage();

Use a try/finally around browser work so the browser is closed even if navigation or processing throws. The measurement window is defined by the start and stop calls: actions that happen before starting or after stopping are not part of that collection.

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

What the JavaScript coverage options do

Puppeteer’s 25.12.0 JSCoverageOptions reference documents these four options:

Option Default Effect
useBlockCoverage true Collect block-level coverage. Set to false for function-level collection.
reportAnonymousScripts false Include dynamically created scripts that do not have a URL.
includeRawScriptCoverage false Include raw V8 script coverage entries in each result where available.
resetOnNavigation true Reset coverage on navigation. It does not guarantee that the previous document’s data can be preserved by changing it to false.

Block-level or function-level data

Block coverage is the default and gives finer-grained execution information. Choose useBlockCoverage: false when function-level reporting is sufficient for your analysis.

Rank #2
Sale
HTML and CSS: Design and Build Websites
  • HTML CSS Design and Build Web Sites
  • Comes with secure packaging
  • It can be a gift option

Anonymous and dynamically generated scripts

Scripts created with eval or new Function may not have a URL and are omitted by default. Set reportAnonymousScripts: true if those scripts matter to the measurement. Such entries generally have URLs beginning with debugger://VM; a script that supplies a //# sourceURL comment can instead be reported under that source URL. See the method reference.

Raw V8 coverage

Leave includeRawScriptCoverage off unless downstream processing needs the raw V8 protocol data. When enabled, an entry can include rawScriptCoverage, typed as the V8 protocol script coverage object. The returned entry shape is described in Puppeteer’s 25.5.0 JSCoverageEntry reference.

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

Why coverage can be empty after navigation

Start collection before navigation if the goal is to include scripts executed while the document loads. Starting after page.goto() excludes that earlier execution.

Do not rely on resetOnNavigation: false to preserve coverage from a document you leave. Puppeteer’s current options reference warns that Chrome may discard the previous page’s JavaScript execution environment and coverage data on navigation. To collect across documents, stop before leaving each document, start a fresh collection on the next one, and merge the resulting reports in your own processing pipeline.

Rank #4
Sale
Web Design with HTML, CSS, JavaScript and jQuery Set
  • Brand: Wiley
  • Set of 2 Volumes
  • A handy two-book set that uniquely combines related technologies Highly visual format and accessible language makes these books highly effective learning tools Perfect for beginning web designers and front-end developers
await page.coverage.startJSCoverage();
await page.goto('https://example.com/first');
const firstPageEntries = await page.coverage.stopJSCoverage();

await page.coverage.startJSCoverage();
await page.goto('https://example.com/second');
const secondPageEntries = await page.coverage.stopJSCoverage();

const allEntries = [...firstPageEntries, ...secondPageEntries];

This example combines the returned arrays; it does not itself deduplicate scripts or create an Istanbul report. The navigation caveat and recommended stop/restart approach are documented in the options reference.

How to read, measure, and export the result

Each result represents a script and carries coverage ranges. The Coverage class reference, version 25.9.0, demonstrates a byte-based calculation: sum each script’s text length and the lengths of its used ranges, then divide used bytes by total bytes. This is one possible metric, not a universal definition of test coverage; choose the measure that matches what you need to assess.

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.

For an Istanbul-compatible report, Puppeteer points to the separate puppeteer-to-istanbul package. Coverage collection alone returns Puppeteer entries; it does not automatically produce Istanbul’s report format.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting common coverage problems

  • No entries or missing page-load execution: Ensure startJSCoverage() runs before page.goto() or other activity being measured.
  • Anonymous scripts are missing: Enable reportAnonymousScripts: true for scripts such as eval or new Function that have no URL.
  • Coverage disappears after navigation: Do not assume resetOnNavigation: false preserves the prior document. Stop collection before navigating, start it again on the next document, and merge the entries.
  • The report granularity is too coarse: Keep useBlockCoverage: true for block-level data; false changes collection to function-level.
  • The processor needs V8 protocol details: Enable includeRawScriptCoverage and check the entry’s rawScriptCoverage field.
  • The output is not in Istanbul format: Convert Puppeteer’s entries with the separate puppeteer-to-istanbul package.

The option defaults cited here come from Puppeteer’s references labelled versions 25.10.0 and 25.12.0; related API pages are labelled 25.5.0 and 25.9.0. Check the documentation and types for the Puppeteer version installed in your project before relying on version-specific behavior.

Or skip the browser setup

If you need a rendered screenshot rather than execution coverage, ScreenshotNeo returns a screenshot or PDF from one GET request. For example, using cURL:

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. It accepts cookie or consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; these steps can be turned off. Bot checks, blank pages, timeouts, failed loads, and cache hits are not billed, and response headers indicate the page verdict and billing status. Its MCP server provides screenshot and PDF tools for AI agents. The Free plan includes 1,000 screenshots a month without a card; paid plans start at $5 for 3,000 shots.

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

Sign up for ScreenshotNeo’s free plan to get 1,000 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.

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. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. 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…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver 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.