---
title: "Freeze the backend's answers with a recorded HAR | Proofline"
description: "A bug that depends on what the server returned is hard to replay a day later, because the server returns something else."
url: https://proofline.sh/learn/har-replay-playwright/
---

[Learning center](/learn/)

# Freeze the backend's answers with a recorded HAR

A bug that depends on what the server returned is hard to replay a day later, because the server returns something else. Playwright can serve a recorded HAR file back to the page, so the page receives exactly the responses the reporter's session got. In our fixture, replay worked with the server stopped, and it also showed two ways a recording silently misses the response you need.

Network outages The Proofline team November 22, 2026 4 min read

## Record the responses

Record a HAR while reproducing, limited to the requests that matter:

```
const context = await browser.newContext({
  recordHar: { path: 'repro.har', mode: 'minimal', urlFilter: '**/api/**' },
});
// reproduce the bug, then:
await context.close(); // the HAR is written on close
```

Or with codegen: `npx playwright codegen --save-har=repro.har --save-har-glob="**/api/**" https://staging.example.test`.

## Replay them

```
const context = await browser.newContext({ serviceWorkers: 'block' });
const page = await context.newPage();
await page.routeFromHAR('repro.har', { url: '**/api/**', notFound: 'abort' });
await page.goto('https://staging.example.test/orders');
```

Requests matching `url` are answered from the file. With `notFound: 'abort'`, the default, a matching request that is not in the file fails. With `'fallback'` it goes to the network. Playwright does not serve requests that a service worker intercepts from the HAR, and recommends blocking workers when replaying, as above. [Playwright: Replaying from HAR](https://playwright.dev/docs/mock#replaying-from-har) · [`page.routeFromHAR()`](https://playwright.dev/docs/api/class-page#page-route-from-har)

## What we saw in a fixture

We recorded two API calls with Playwright 1.63, `GET /api/slow?q=apple` and `POST /api/slow?q=pear` with body `x=1`, then replayed with `notFound: 'abort'`:

| Replayed request | Result |
| --- | --- |
| `GET ?q=apple` | 200 with the recorded body |
| `GET ?q=banana`, not recorded | `Failed to fetch` |
| `POST ?q=pear`, body `x=1` | 200 with the recorded body |
| `POST ?q=pear`, body `x=2` | `Failed to fetch` |

The server received none of the four requests. Matching uses the URL and method, and for the POST also the body, so a replay with different input does not silently get the wrong recorded answer.

The first recording attempt went wrong. The page's code had not read the response bodies, and the HAR recorded the responses with no content. Replaying them returned 200 with an empty body. Record with a page that consumes the responses, as the real app does, and open the HAR to check that each entry you need has `content.text`.

## When a HAR replay is the right tool

| Situation | HAR replay helps? |
| --- | --- |
| The bug depends on a particular API response that has since changed | Yes: the page gets the old response |
| The maintainer has no access to the reporter's environment or data | Yes, once personal data is removed from the file |
| The bug is in how the server computed the response | No: replay skips the server |
| The bug depends on timing between responses | Not by itself: replay answers as fast as it can. [Hold one response](/learn/force-response-order/) to control order. |
| Requests include a timestamp, nonce or random ID in the URL or body | Only if you make them match, since a different value is a different request |

## Clean the file

A HAR contains headers, cookies and bodies. Record from a test account, keep the `urlFilter` narrow, and edit out personal data before sharing. A replayed response must still parse, so replace values with synthetic ones of the same type and shape, rather than deleting fields. [Share a HAR file](/learn/share-har-file/) covers what to remove.

## Worked example: a price list that broke for one day

This example is fictional. On Tuesday, a tester sees the pricing table render "NaN" for one plan. By Wednesday the pricing API has been fixed and nobody can see it, but the frontend's handling still needs a fix.

The tester had recorded a HAR of `/api/**` while reproducing. The developer replays it with `routeFromHAR` and sees "NaN" again: the recorded response had `"price": null` for the plan. The frontend formatted `null` as a number. With the replay, the developer wrote a test that loads the page against the recorded response and fixed the formatter to show "Contact us" for a missing price.

## Questions

### Can I replay a HAR exported from Chrome DevTools?

Playwright reads HAR files, and a DevTools export is one. Chrome's default export removes some headers, and its bodies are only those DevTools kept, so check the entries you need before relying on it.

### Can I edit a response in the HAR?

Yes. It is JSON, so you can change a value to test a hypothesis, such as setting `price` back to a number and confirming the table renders. Say in the report which entries you edited.

### What does `update: true` do?

It records into the file instead of replaying, which refreshes a recording against the current server. Use it to create a new recording, not to reproduce an old one.

Return to [reproducing what someone else saw](/learn/replay-browser-bug-report/) for the other layers a replay needs.

## One month of free code review.

New organizations get one calendar month of hosted code review for private and public GitHub repositories. No card or cloud connection required. [Eligibility and fair-use terms](/free-code-review/).

[Start free with GitHub](https://proofline.sh/orgs/plan?offer=free_month)

## Related reading

-   ### [Share a HAR file without handing over a session](/learn/share-har-file/)
    
    Data leaks The Proofline team November 20, 2026 4 min read
    
-   ### [Make a race reproduce every time by holding one response](/learn/force-response-order/)
    
    Network outages The Proofline team November 22, 2026 4 min read
