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 DealsSlow PC?RecommendedPC slow today? Run a repair scan before it gets worseResolve common Windows issues and optimize system performance.Scan Now×
Skip to content
World desk3 min

How to Stop and Save a Puppeteer Trace

Use Puppeteer’s tracing API to record browser activity and save it to a file—or retrieve the trace bytes and persist them in your own code.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Start tracing with page.tracing.start({ path: 'trace.json' }), run the browser activity you want to record, then await page.tracing.stop(). The path option tells Puppeteer to write the trace to disk. Without it, Puppeteer does not save a file automatically; your code can instead handle the trace data returned by stop().

Save a trace directly to a file

Tracing covers the browser activity between the awaited start() and stop() calls. Set path when you want Puppeteer to write the output file.

As an Amazon Associate I earn from qualifying purchases.

const puppeteer = require('puppeteer');

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

    await page.tracing.start({ path: 'trace.json' });
    try {
      await page.goto('https://example.com');
      // Run the interactions or page work you want to capture here.
    } finally {
      await page.tracing.stop();
    }
  } finally {
    await browser.close();
  }
})();

The inner finally makes the stop call run even if the navigation or an interaction throws. Keep the browser open until tracing has stopped. The resulting trace can be opened in Chrome DevTools or a timeline viewer.

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

Choose between a file and trace data

Method Who persists the trace? Use it when
start({ path: 'trace.json' }) Puppeteer writes directly to the specified path. You want a trace file without handling its bytes in application code.
start() without a path Your application. stop() can resolve to a Uint8Array of trace data. You need to process or store the bytes yourself, or choose an output path dynamically.

The documented return type of stop() is Promise<Uint8Array | undefined>. Account for the possibility of undefined; do not assume that calling stop() always creates a file.

const fs = require('node:fs/promises');

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

if (traceData) {
  await fs.writeFile('trace.json', traceData);
}

Configure what the trace captures

Puppeteer’s tracing options include path, categories, screenshots, and bufferSize. Screenshots are off by default. Categories can be included or excluded; prefix a category with a minus sign to exclude it.

await page.tracing.start({
  path: 'trace.json',
  screenshots: true,
  categories: ['devtools.timeline', '-disabled-by-default-devtools.timeline'],
});

Choose categories for the events you need to inspect rather than assuming every trace must use the same set. The documented options also describe bufferSize: when omitted or set to zero, Chromium’s default is 200 MB (200,000 KB). That default is version-sensitive implementation guidance, not a fixed limit guaranteed across all Chromium versions.

Work within the one-trace-per-browser limit

Puppeteer documents that only one trace can be active at a time per browser. Stop the current trace before starting another in that browser. If you need separate captures, run them sequentially rather than overlapping tracing sessions.

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

Open and inspect the saved trace

After stop() has completed, open the resulting trace file in Chrome DevTools or a compatible timeline viewer. If the file is missing, first confirm that start() received a path and that the application awaited stop() before closing the browser or ending the process.

Troubleshoot common problems

  • No file appears: If tracing started without path, Puppeteer did not write a file; persist the returned bytes yourself. If a path was set, make sure the process reached and awaited stop().
  • stop() returns no bytes: The documented return type allows undefined. Check the result before writing it, and use a path if direct file output is what you need.
  • A second trace cannot start: Only one trace can be active per browser. Await the first trace’s stop() before starting the next.
  • The trace lacks screenshots: Screenshot capture defaults to off. Set screenshots: true when starting the trace.
  • Trace options behave differently in your installation: Puppeteer documentation pages may refer to different releases. Check the API documentation matching your installed Puppeteer version before relying on version-sensitive behavior.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Or skip the browser setup

A trace records browser timeline activity; a website screenshot is a different output. If you need a clean screenshot rather than trace events, ScreenshotNeo offers a screenshot API and MCP server. Its request format and options are in the ScreenshotNeo documentation.

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

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

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.

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
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

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.