October DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan NowOctober DealsAmazon USDeal season is back - check today's better picksAmazon US: current deals, useful picks and tech finds.See Picks×
Skip to content
World desk3 min

How to Stop CSS Coverage in Puppeteer

Stop Puppeteer CSS coverage with page.coverage.stopCSSCoverage() after the navigation and interactions you want included. See what the returned entries mean and what they leave out.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Call await page.coverage.stopCSSCoverage() after the navigation and interactions you want to measure. It returns an array of stylesheet coverage entries; it does not remove CSS or decide what is safe to delete.

Stop CSS coverage after the page activity you want to measure

Start coverage before navigating, exercise the page states that matter, then stop it and inspect the returned entries:

As an Amazon Associate I earn from qualifying purchases.

const page = await browser.newPage();

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

// Perform the interactions you want included in this capture.
const entries = await page.coverage.stopCSSCoverage();

for (const entry of entries) {
  console.log(entry.url, entry.ranges);
}

The stop call is page.coverage.stopCSSCoverage(). Puppeteer’s Coverage.stopCSSCoverage() API documentation describes the result as coverage entries for stylesheets. Puppeteer’s Coverage class guide shows the lifecycle: start coverage, navigate, stop coverage, then process the entries. Use the public page API rather than constructing the Coverage class directly; its constructor is marked internal.

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.

What the returned entries tell you

Each entry contains stylesheet information, including its URL, text, and ranges identified as used during the captured run. These are observations from the page states and interactions exercised while coverage was active, not a site-wide inventory or a ready-made CSS-removal plan.

Puppeteer’s class guide demonstrates estimating a used-byte percentage by summing each entry’s text length for the total and the lengths of its ranges for the used portion:

const totalBytes = entries.reduce((sum, entry) => sum + entry.text.length, 0);
const usedBytes = entries.reduce(
  (sum, entry) => sum + entry.ranges.reduce(
    (rangeSum, range) => rangeSum + range.end - range.start - 1,
    0
  ),
  0
);

const usedPercent = totalBytes === 0 ? 0 : (usedBytes / totalBytes) * 100;
console.log(`Used CSS in this run: ${usedPercent.toFixed(1)}%`);

This is an illustrative calculation over the captured entries, not a benchmark or proof that the remaining CSS can be deleted. Before removing styles, repeat coverage across relevant routes, responsive layouts, menus, dialogs, and other UI states, then validate the change against those states.

Navigation behavior and a documented limitation

The startCSSCoverage() API documentation lists resetOnNavigation with a default of true. If your measurement depends on how coverage behaves across navigation, set the option deliberately and verify it against the documentation for your installed Puppeteer version.

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

Puppeteer documents this limitation for CSS coverage: “CSS Coverage doesn’t include dynamically injected style tags without sourceURLs.” See the stopCSSCoverage() documentation. A report that omits injected styles may therefore reflect this documented limitation rather than a failure to stop coverage.

Troubleshooting

  • The call fails because coverage was not started: call and await page.coverage.startCSSCoverage() on that page before collecting coverage.
  • The entries miss styles used after initial load: keep coverage active while performing the interactions that use those styles, then stop it afterward.
  • Injected styles are missing: Puppeteer documents that dynamically injected style tags without sourceURLs are not included in CSS coverage.
  • The result seems to reset at navigation: check the resetOnNavigation setting and the documentation matching your installed version; the documented default is true.
  • You expected unused CSS to be deleted: stopping coverage returns data to inspect. It does not modify stylesheets; deletion and validation are separate steps.

Or skip the browser setup

If your goal is a clean screenshot rather than CSS coverage, ScreenshotNeo can capture a page with one API request. It is not a replacement for Puppeteer’s coverage data and does not identify unused CSS.

See the ScreenshotNeo API documentation. For example, this cURL request saves a WebP screenshot of the target URL:

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://example.com -o shot.webp

ScreenshotNeo removes cookie banners, newsletter popups, and chat widgets before the shot; bot checks, blank pages, and failed loads are never billed. Its MCP server lets AI agents take screenshots, and the free plan includes 1,000 screenshots a month with no card; paid plans start at $5 for 3,000.

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

Sign up for ScreenshotNeo’s free plan.

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

Frequently Asked Questions

Does stopCSSCoverage() include CSS from a dynamically injected style tag?

Not if the injected style tag has no sourceURL; Puppeteer’s stopCSSCoverage() documentation names this as a CSS coverage limitation.

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. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Crashes, No Sound, or Screen Glitches?Free driver scan
PC Slower Than It Used to Be?Free scan - under a minute

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.