MarketSquare / MarketSquare/robotframework-browser

Support `content`, `mode` and `urlFilter` keys in the `recordHar` option of `New Context`

Open
#5,113 0 comments 0 reactions 1 assignee View on GitHub

@Snooz82 is already working on this.

Since Aug 6, 2026.

enhancement
Dominant language
Python
Stars
655
Forks
147
Avg merge
5h 27m
Merged PRs (30d)
59

Description

## Use case

`New Context recordHar=...` already records HAR files, but the `RecordHar` TypedDict only accepts `path` and `omitContent`. That means every recording is a *full* HAR of *all* traffic with embedded bodies — typically many megabytes including analytics, fonts and images. Users who want a small, focused HAR (e.g. only the `**/api/**` calls of a login flow) have no way to get one and must post-process the file externally.

This is also a prerequisite for the planned `Route From HAR` keyword (network-mocking milestone): the record-once/replay-forever workflow only works in practice if the recorded HAR is small enough to check into the repository. `mode=minimal` records only the fields needed for replay, and `urlFilter` limits recording to the interesting endpoints — together they turn HARs into practical, check-in-able test fixtures.

## Proposed keyword / arguments

Extend the `RecordHar` TypedDict (`Browser/utils/data_types.py`) with three optional keys — no keyword signature changes:

- `content`: `embed` (default) | `attach` | `omit` — how response bodies are stored (`attach` writes them as separate files next to the HAR).
- `mode`: `full` (default) | `minimal` — `minimal` records only information necessary for HAR replay, dropping sizes, timings, pages etc.
- `urlFilter`: glob or regex string — only matching requests are recorded.

```robotframework
*** Test Cases ***
Record Minimal API HAR For Later Replay
${har}= Create Dictionary
... path=${CURDIR}/fixtures/login-api.har
... mode=minimal
... urlFilter=**/api/**
New Context recordHar=${har}
New Page ${LOGIN_URL}
Fill Secret id=password $PASSWORD
Click id=submit
Close Context # HAR is written on context close
```

## Playwright API

[browser.newContext](https://playwright.dev/docs/api/class-browser#browser-new-context) — `recordHar.content`, `recordHar.mode`, `recordHar.urlFilter` options (see also the `recordHarContent`/`recordHarMode`/`recordHarUrlFilter` aliases in the Playwright docs).

## Implementation notes

- `Browser/utils/data_types.py`: add the three optional keys to the `RecordHar` TypedDict with docs and examples; small enums or `Literal` types for `content`/`mode`.
- `node/playwright-wrapper`: context options already travel as serialized JSON to `browser.newContext`; verify the keys pass through unmodified (likely no proto change needed).
- Docs regeneration (`inv build` stubs) and one atest recording with `mode=minimal` + `urlFilter`, asserting the HAR contains only matching entries.

## Backwards compatibility

Additive optional TypedDict keys with `total=False`; existing `recordHar` dicts containing only `path`/`omitContent` keep working unchanged, and omitting the new keys preserves Playwright's current defaults (`content=embed`, `mode=full`, no filter).

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.