Skip to content

Record a HAR file

View as Markdown

Set up your agent

Give your coding agent a Steel browser and the Steel skills, so that it browses and writes Steel code the right way. Learn more

Install the Steel CLI. It signs you in and installs the skills for your coding agents.

curl -fsS https://setup.steel.dev | sh

Or send this prompt to your coding agent, and it does the same:

Read https://setup.steel.dev/install.md and follow it to set up Steel for this coding client.
Then continue my requested task using the installed Steel skill.

Set up your agent →

A HAR file (HTTP Archive) holds a browser's network traffic: each request and response, with its headers, cookies, timings and body. Record one to study how a site loads its data, to call a site's API directly, or to keep a full record of a run. Steel's logs hold each request's URL, method and status, but not its headers or body.

Steel does not save HAR files itself. Playwright records one over its connection to the session, and writes it on the machine that runs your code.

Before you begin

Put your Steel API key in the STEEL_API_KEY environment variable. Then install the Steel SDK and Playwright 1.60 or later, the first version with tracing.startHar. You do not need to run playwright install, because the program uses a browser that Steel runs.

npm install steel-sdk playwright

Record the network traffic

This program starts a HAR recording and a Playwright trace on the session's browser context, opens a page, and saves both files.

har.mts
import Steel from "steel-sdk";
import { chromium } from "playwright";

const client = new Steel();
const session = await client.sessions.create();

try {
  const browser = await chromium.connectOverCDP(session.websocketUrl);

  try {
    const context = browser.contexts()[0];
    const page = context.pages()[0] ?? (await context.newPage());

    const timestamp = Date.now();
    const harFile = `recording-${timestamp}.har`;
    const traceFile = `trace-${timestamp}.zip`;

    await context.tracing.startHar(harFile, {
      urlFilter: "**/*",
      content: "embed",
      mode: "full",
    });
    await context.tracing.start({
      screenshots: true,
      snapshots: true,
      sources: true,
    });

    try {
      await page.goto("https://news.ycombinator.com");
    } finally {
      try {
        await context.tracing.stop({ path: traceFile });
      } finally {
        await context.tracing.stopHar();
      }
    }

    console.log(`HAR: ${harFile}, Trace: ${traceFile}`);
  } finally {
    await browser.close();
  }
} finally {
  await client.sessions.release(session.id);
}

The program records the browser context that the session already has, contexts()[0], and does not create a new one. The options of startHar (start_har in Python) set what the HAR file keeps:

OptionWhat it does
urlFilterKeeps only the requests whose URL matches this glob or regular expression. **/* keeps every request.
contentembed keeps each response's body in the HAR file. When the path ends in .zip, the default is attach, which saves the bodies as separate files in the archive.
modefull keeps the sizes, timings, cookies and pages. minimal keeps only what Playwright needs to replay the requests.

The trace holds a snapshot of the page's DOM and a screenshot at each action. So it has the page after its scripts ran, which the HAR file does not have. Playwright's tracing.startHar and Trace viewer docs have every option.

Run the program:

npx tsx har.mts

It writes both files in the folder where it runs when it stops the recordings, and prints their names:

HAR: recording-1795058880467.har, Trace: trace-1795058880467.zip

On a server whose disk is read-only but for a temporary folder, such as AWS Lambda, write them to /tmp and upload them to your own storage.

Check that it worked

Open the HAR file in the Network panel of Chrome DevTools, which imports HAR files, as Chrome's Network reference explains. It lists the requests that loaded news.ycombinator.com, each with its headers and its response. Then open the trace with npx playwright show-trace and the trace's file name (playwright show-trace in Python). It shows the goto action with a snapshot of the page.

What a HAR file leaves out

  • The first requests of a tab that a page opens, such as a link with target="_blank" or a call to window.open. They start before Playwright attaches to the tab. A tab that your code opens with newPage (new_page in Python) and then goto is recorded from its first request.
  • The page after its scripts ran. The HAR file has the HTML that the site sent, and the trace has the page as it showed.

Next steps

Reviewed November 18, 2026
Was this page helpful?