Skip to content

fix(runner): record artifacts for flow created browser contexts#1393

Open
Chase J (chajac) wants to merge 4 commits into
mainfrom
record-flow-created-contexts
Open

fix(runner): record artifacts for flow created browser contexts#1393
Chase J (chajac) wants to merge 4 commits into
mainfrom
record-flow-created-contexts

Conversation

@chajac

Copy link
Copy Markdown
Contributor

flows run --video on --har on --trace on silently records nothing for flows whose helpers create their own browser context. The telltale artifact is a ~218-byte HAR containing "entries": [], no video files, and an empty trace, while the flow itself runs and passes fine.

Playwright’s recordVideo / recordHar / tracing are per-browser-context options. createLaunch only instrumented the single context it created inside launch(), then returned the raw browser handle. Flow helper code commonly does:

const { browser } = await launch({ ... });
const context = await browser.newContext({ ... });
const page = await context.newPage();

Any flow following this pattern (i.e a shared login helper that builds its own context) produced no artifacts locally, with no workaround available via flags.

Overview of Changes

  • createLaunch now patches browser.newContext in place, so every context CLI created or flow created funnels through one instrumentation path: recording options merged (caller options win on conflicts), default timeout applied, tracing started, ordered teardown registered.
  • Each context gets indexed artifact paths (<flow>.har, <flow>-2.har same for trace zips). This also fixes the preexisting issue where multiple launch() calls in one flow overwrote each other’s HAR/trace. retain-on-failure cleanup now removes every assigned per context path, not just the base one.

Testing

Flow pattern published 1.2.0 this branch
Flow using launch()'s context ✅ video + HAR ✅ unchanged
Flow using own browser.newContext() ❌ no video, HAR entries: [] ✅ video + populated -2.har
bun run typecheck
bun run lint
bun run format:check
bun run knip
bun run test
bun run build

Checklist

  • Changes follow the code style of this project
  • Self-review completed
  • Tests added/updated (or not applicable)
  • No breaking changes (or described below)

Playwright recording options (recordVideo/recordHar/tracing) are
per-context, but createLaunch only instrumented the context it created —
contexts a flow made via browser.newContext() recorded nothing (empty
HAR, no video, empty trace).

Patch browser.newContext in place so every context funnels through one
instrumentation path: recording options merged (caller wins), default
timeout set, tracing started, and ordered teardown registered. Each
context gets indexed HAR/trace paths (flow.har, flow-2.har, ...), which
also fixes multiple launch() calls overwriting one another's artifacts.
Retain-on-failure cleanup now removes every assigned per-context path.

Known gap: a context the flow closes itself flushes video/HAR but loses
its trace (tracing must stop before close) — tracked in WIZ-11062.
@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: cb957c95-31fc-4d50-b599-d3cdc4872596

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch record-flow-created-contexts

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/domains/runner/createLaunch.ts`:
- Around line 107-110: Update the context creation flow around nextSetup,
originalNewContext, and trackContext to derive the HAR artifact path from the
final merged options, so an opts.recordHar value is tracked instead of the
discarded indexed setup path. Ensure artifactPaths() and cleanup use this
effective caller-provided path, and add a regression test covering a
caller-supplied HAR path.
- Around line 69-83: Update the closeAll teardown flow in createLaunch so it
memoizes and returns the in-progress teardown promise instead of returning
immediately when closed is already true. Ensure concurrent signal-driven
closeAll() and normal cleanup() await the same tracing and close operations
before runWebFlow proceeds to unlink artifacts.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 58de2e83-7a15-4541-b2be-4cb0a8da9fa0

📥 Commits

Reviewing files that changed from the base of the PR and between 948fb5e and a9b85c9.

📒 Files selected for processing (9)
  • src/domains/runner/createLaunch.contexts.test.ts
  • src/domains/runner/createLaunch.test.ts
  • src/domains/runner/createLaunch.ts
  • src/domains/runner/runWebFlow.har.test.ts
  • src/domains/runner/runWebFlow.ownContext.fixture.ts
  • src/domains/runner/runWebFlow.trace.test.ts
  • src/domains/runner/runWebFlow.ts
  • src/domains/runner/runWebFlowUtils.ts
  • src/domains/runner/web/artifactPaths.ts
💤 Files with no reviewable changes (1)
  • src/domains/runner/runWebFlowUtils.ts

Comment thread src/domains/runner/createLaunch.ts Outdated
Comment thread src/domains/runner/createLaunch.ts Outdated
@chajac Chase J (chajac) changed the title fix(runner): record artifacts for flow-created browser contexts fix(runner): record artifacts for flow created browser contexts Jul 15, 2026
@chajac
Chase J (chajac) marked this pull request as ready for review July 15, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant