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 desk4 min

How to Start a Performance Trace with Puppeteer

Use Puppeteer's page.tracing API to bracket a navigation or interaction, save trace.json, and open the result in Chrome DevTools or the timeline viewer.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start a trace with page.tracing.start() before the page load or interaction you want to measure, perform that work, then call page.tracing.stop(). Give start() a file path to save the trace, or omit it and use the returned Uint8Array. Open the resulting trace in Chrome DevTools or the timeline viewer.

Capture a page load

After launching Puppeteer and creating a page, start tracing immediately before navigating. Stop tracing once the navigation has completed:

As an Amazon Associate I earn from qualifying purchases.

import puppeteer from 'puppeteer';

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

  await page.tracing.start({ path: 'trace.json' });
  await page.goto('https://example.com');
  await page.tracing.stop();
} finally {
  await browser.close();
}

This writes the trace to trace.json in the process’s current working directory. Puppeteer’s Tracing class documentation describes opening the resulting file in Chrome DevTools or the timeline viewer.

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

Capture an interaction instead of navigation

The trace brackets the work you want to inspect. For an interaction, start tracing after the page is ready but immediately before the action, then stop after the action and any relevant follow-up work finish:

await page.goto('https://example.com');
await page.tracing.start({ path: 'interaction-trace.json' });
await page.locator('button').click();
await page.tracing.stop();

Starting too early includes unrelated loading or setup activity; starting too late misses the work under investigation. The documented API begins tracing for the current page, so use the page whose activity you intend to capture.

Save to a file or keep trace bytes in memory

The path option controls whether Puppeteer writes the trace to disk. With a path, stop() ends the capture after the file is written. Without a path, the stop result contains the trace as a Uint8Array, which you can pass to code that stores or processes binary data:

await page.tracing.start();
await page.goto('https://example.com');
const traceBytes = await page.tracing.stop();

// traceBytes is a Uint8Array; write or upload it with your preferred storage API.

For example, in Node.js you can write the bytes with the built-in filesystem module:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import { writeFile } from 'node:fs/promises';

await writeFile('trace.json', traceBytes);

See Puppeteer’s TracingOptions reference for the currently documented return behavior and available options.

Choose trace categories and screenshots

The default start-and-stop flow is the simplest place to begin. Optional categories lets you control which tracing categories are included; a category prefixed with - is excluded. The screenshots option controls screenshot capture within the trace.

await page.tracing.start({
  path: 'trace.json',
  categories: ['devtools.timeline', '-disabled-by-default-v8.cpu_profiler'],
  screenshots: true,
});
await page.goto('https://example.com');
await page.tracing.stop();

Category availability and useful combinations depend on the Chromium tracing configuration. Add options only when you need the events or visual context they provide, and consult the live Puppeteer options reference because API details can change over time.

Observe the one-trace-per-browser limit

Only one trace can be active at a time in a browser. If you need separate captures, stop the current trace before starting the next one. This is particularly important in loops or test suites: ensure every successful start is paired with a stop, including when the measured operation throws.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
await page.tracing.start({ path: 'first.json' });
try {
  await page.goto('https://example.com/first');
} finally {
  await page.tracing.stop();
}

await page.tracing.start({ path: 'second.json' });
try {
  await page.goto('https://example.com/second');
} finally {
  await page.tracing.stop();
}

Inspect or troubleshoot the trace

Open the trace

Load the saved trace file in Chrome DevTools or the timeline viewer to inspect recorded activity. Puppeteer documents these as trace viewers; the exact analysis workflow depends on what you are investigating.

Common problems and fixes

  • No trace file appears: confirm that start() received a path. Without one, retrieve the Uint8Array returned by stop() and save or process it yourself.
  • The capture is empty or misses the event: start tracing before the navigation or interaction, and stop only after the work you want included has run.
  • Starting another trace fails or conflicts with the current capture: only one trace may be active per browser. Stop the existing trace before beginning another.
  • The trace is unexpectedly large: narrow the capture window or review the selected categories and whether screenshots are needed. The options reference notes Chromium’s default trace buffer size is 200 MB when bufferSize is omitted or zero; avoid treating that configuration default as a guarantee that every capture will fit.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

ScreenshotNeo is a website screenshot API, not a performance-tracing replacement: it returns a page screenshot or PDF rather than Puppeteer’s trace data. If you need a clean visual capture without managing browser setup, one GET request is enough. See the ScreenshotNeo documentation for request options.

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

ScreenshotNeo accepts cookie/consent banners and removes more than 60 known consent platforms, newsletter popups, and chat widgets before capture; each step can be turned off. Bot checks, blank pages, failed loads, timeouts, and cache hits are not billed, and response headers identify the page verdict and billing status. Its MCP server lets AI agents use screenshot and PDF tools. The free plan includes 1,000 screenshots a 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.

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

Frequently Asked Questions

Can Puppeteer trace a single page interaction?

Yes. Start tracing immediately before the interaction and stop after the relevant work completes; the capture applies to the current page.

Does a Puppeteer trace replace a screenshot?

No. A trace records performance activity for inspection, while a screenshot captures the page’s visual appearance. ScreenshotNeo produces screenshots or PDFs, not Puppeteer trace data.

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
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.