Skip to content

Browser mode trace view follow-ups #10156

Closed
4 of 4 issues completed
Closed

Description

@hi-ogawa

Follow-up issue for the built-in browser trace view introduced in:

The MVP intentionally keeps browser.traceView focused on trace collection, replay, and basic debugging. This issue tracks post-MVP follow-ups that were discussed during the PR or discovered immediately after it landed, but left out because they need broader architecture, product, or fidelity decisions.

MVP Scope Summary

The MVP delivers the core loop:

  • collect trace entries for actions, expect.element, marks, and lifecycle events
  • record status, timing, selectors, source locations, DOM snapshots, viewport, and scroll state
  • show traces in Browser UI, Vitest UI, and HTML reporter
  • support failed-step highlighting, selector highlight when resolvable, retries/repeats, and basic replay fidelity

Follow-Up Areas

  1. Replay fidelity
  2. Workflow defaults and entry points
  3. Viewer UI additions
  4. Artifact lifecycle and transport

Replay Fidelity

For deeper background on the current DOM snapshot/replay landscape and rrweb/Playwright/Cypress trade-offs, see: https://gist.github.com/hi-ogawa/402813e81847cfa5ed2b593256737d75

What replay should preserve beyond the current DOM-snapshot MVP, including resource fidelity, pseudo-state, and replay safety.

ℹ️ Extend snapshot fidelity coverage

Current MVP behavior:

  • Trace view captures DOM shape, form state, viewport, scroll state, same-origin readable CSS, optional loaded image pixels, and optional canvas pixels.
  • Some resources remain URL-backed.

Known follow-ups:

  • Constructable/adopted stylesheets are not preserved.
  • CSS background images and font files referenced from CSS remain URL-backed.
  • Snapshot capture currently reflects resource readiness at snapshot time, so late-loading images or stylesheets can be absent from replay if they were not yet loaded/readable when the snapshot was taken.
  • External image/resource fixtures should be made deterministic.
  • Existing external stylesheet/font tests are currently fixture-quality placeholders rather than strong fidelity tests.
  • Viewport/scroll replay needs dedicated UI e2e coverage.
  • Snapshot-time pseudo-state is still limited and should continue to be treated as replay polish rather than the core contract.

Why this is post-MVP:

  • The MVP documents the fidelity boundary and provides useful replay for normal component tests.
  • Snapshot-time readiness is also a defensible default for MVP: in many cases users should explicitly await the state they want to inspect, and current tests already rely on that pattern for resources such as images.
  • Full resource capture is broader than trace-view UI and may require a general resource store or attachment strategy.

Possible direction:

  • Add deterministic CORS/non-CORS fixtures.
  • Add real font and external stylesheet fixtures.
  • Evaluate a resource store for CSS subresources, fonts, and external assets.
  • Add UI e2e coverage for viewport/scroll replay.
  • Continue improving high-value pseudo-state metadata where it materially improves debugging without redefining the replay contract.

Relevant files / fixtures:

  • packages/browser/src/client/tester/trace.ts
  • test/browser/fixtures/trace/exotic.test.ts
  • test/browser/fixtures/trace/resources.test.ts
  • test/browser/fixtures/trace/styles.test.ts
  • test/browser/fixtures/trace/viewport.test.ts
ℹ️ Sanitize replayed scripts without weakening the default sandbox

Current MVP behavior:

  • Default replay uses a sandbox without allow-scripts.
  • This is intentional.
  • If the rebuilt snapshot contains script nodes, the browser can log blocked script execution warnings.

Why this is post-MVP:

  • The warning is noisy but does not break the core replay workflow.
  • Sanitizing serialized script nodes safely requires preserving enough DOM shape and rrweb node identity while preventing execution.

Possible direction:

  • Make script nodes inert for non-recordCanvas traces before replay.
  • Keep the current stronger sandbox by default.
  • Avoid using srcdoc as a fake fix; it likely changes the warning source label rather than the execution behavior.

What not to do:

  • Do not weaken the default iframe sandbox except for documented recordCanvas replay needs.

Relevant files:

  • packages/ui/client/components/trace/TraceView.vue

Workflow Defaults and Entry Points

How users enable trace view and land in the right workflow/surface.

ℹ️ Decide trace-view workflow defaults / presets

Current MVP behavior:

  • browser.traceView only enables collection and trace-view UI surfaces where they are already available.
  • Users explicitly choose the surrounding workflow.

Examples:

# Watch mode, normal browser UI. Trace viewer appears next to the live browser view.
pnpm test --browser.traceView

# Watch mode, pure Vitest UI. Browser/tester runs in a separate headless browser.
pnpm test --browser.traceView --browser.headless --ui

# Watch mode, pure Vitest UI plus a separate headed browser driver window.
pnpm test --browser.traceView --browser.headless=false --browser.ui=false --ui

# Static HTML reporter.
pnpm test --browser.traceView --browser.headless --reporter=html
pnpm dlx serve ./html/

Why this is post-MVP:

  • An earlier, more opinionated direction treated --browser.traceView as a trace-first preset.
  • That was reverted for MVP so trace view stays additive and users specify each variant explicitly.
  • Reintroducing presets would be a product/config decision, not a collector/viewer correctness fix.

Possible direction:

  • Keep the explicit current behavior but improve docs around the workflow matrix.
  • Add a dedicated preset/alias later if trace-first workflows are common enough.
  • Consider whether watch mode and run mode should have different trace-view convenience behavior.
  • Avoid silently changing browser headed/headless defaults without a clear migration story.

What not to do:

  • Do not make --browser.traceView imply headless/UI/reporter presets without an explicit product decision.

Relevant files / docs:

  • packages/vitest/src/node/config/resolveConfig.ts
  • docs/guide/browser/trace-view.md
ℹ️ Revisit tall viewport size being default (Improve trace viewer replay ergonomics for large/tall viewports)

Current MVP behavior:

  • The replay iframe uses the captured browser viewport size, which default size being tall 414x896 targeted for current browser live view iframe layout in the UI.
  • This is faithful, but tall/mobile-shaped default viewports can make the trace pane feel like nested scrolling UI.

Why this is post-MVP:

  • This is mainly a workflow/default-experience question.
  • Changing runtime viewport defaults would affect test behavior.
  • Any viewer-side scaling or layout treatment should be designed without compromising faithful replay.

Possible direction:

  • Add zoom or scale-to-fit controls to the replay pane.
  • Keep captured viewport dimensions as the source of truth.
  • Reuse ideas from existing BrowserIframe viewport controls where appropriate.
  • Consider whether different trace-view workflows should present large captured viewports differently by default.

What not to do:

  • Do not change browser runtime viewport defaults just to improve trace pane ergonomics.

Relevant files:

  • packages/browser/src/client/tester/trace.ts
  • packages/ui/client/components/trace/TraceView.vue

Viewer UI Additions

Higher-level viewer capabilities beyond the MVP replay pane, including features that may require metadata or transport changes under the hood.

ℹ️ General design UI/UX polish

Some ideas by Raul

Image
ℹ️ Add editor-to-trace reverse navigation

reverted prototype in mvp pr

Current MVP behavior:

  • Selecting a trace step already opens its source location in the Editor tab when available.

Post-MVP direction:

  • Show trace markers in the source editor and let users jump from a source line back to matching trace steps.

Why this is post-MVP:

  • This is viewer/editor UX work, not a trace data contract gap in the MVP.
  • It couples trace-view state to the global CodeMirror lifecycle and custom gutter setup.
  • A prior prototype showed the idea is feasible but too much UI/editor architecture for MVP.

Possible direction:

  • Build an index of file -> line -> stepIndexes for the active trace.
  • Add CodeMirror gutter markers for the active trace.
  • Clicking a marker selects or cycles trace steps for that line.
  • Revisit after trace pane state and layout are stable.

Relevant files / history:

  • packages/ui/client/components/trace/TraceView.vue
  • packages/ui/client/composables/trace-view.ts
  • prior prototype: 8cee41fc3 and revert 8f2e5fec6
ℹ️ Preserve original locator selectors for trace metadata

Current MVP behavior:

  • Trace entries use the selector available at record time.
  • For provider-specific paths, especially WebDriverIO, that selector may already be lowered from the user-facing locator into an internal/provider-specific selector.

Known symptoms:

  • WebDriverIO shadow DOM marks can surface selectorResolution: "error" when lowered selectors such as >>>... are used for snapshot lookup.
  • Some WebDriverIO failed actions can throw before the provider command trace recording path starts, so the failed action entry is missing and only the lifecycle failure is recorded.

Why this is post-MVP:

  • The user-facing reason to do this is better trace-view correctness and usability.
  • Fixing this properly requires separating trace metadata from provider command payloads.
  • A narrow parser workaround would hide the symptom while preserving the wrong coupling.

Possible direction:

  • Add explicit trace metadata to command/action paths.
  • Separate user-facing selector from snapshotSelector.
  • Preserve locator intent on locator instances before provider lowering.
  • Add a WebDriverIO failed-resolution wrapper so failures before command execution still produce action trace metadata.

What not to do:

  • Do not special-case WebDriverIO >>> stripping as the main selector fix.
  • Do not make args[0] a stronger trace metadata contract.

Relevant files:

  • packages/browser/src/client/tester/tester-utils.ts
  • packages/browser/src/client/tester/trace.ts
  • packages/browser/src/client/tester/locators/index.ts
  • test/browser/fixtures/trace/expect.test.ts
  • test/browser/fixtures/trace/exotic.test.ts
ℹ️ Stream trace entries incrementally in watch mode so replay can look live/in-progress

Current MVP behavior:

  • In watch mode, the trace view updates from attempt-complete trace artifacts rather than from a continuously advancing in-progress trace stream.

Why this is post-MVP:

  • The main motivation is viewer UX, not just transport efficiency.
  • A more live/in-progress trace view, similar to Playwright's UI, changes how the viewer consumes and updates trace state while a run is still happening.
  • That may still require transport changes, but the product goal here is the watch-mode experience rather than payload/storage policy by itself.

Possible direction:

  • Stream trace entries incrementally during watch mode.
  • Let the trace pane render partial/in-progress replay instead of waiting for the attempt-complete payload.
  • Decide whether run mode should keep the simpler attempt-end artifact path.
  • Keep this distinct from retention and storage policy work.
ℹ️ Model nested trace groups

Current MVP behavior:

  • page.mark(name, fn) records the grouped mark at the end, while inner actions are recorded individually.
  • Nested grouping is not represented in the trace-view step model.

Why this is post-MVP:

  • The motivating feature is the trace-view step list and grouping UX, even though it likely requires richer trace metadata under the hood.
  • The flat step list is sufficient for MVP debugging.

Possible direction:

  • Add parent/child or span metadata to trace entries.
  • Render collapsible groups in the step list.
  • Decide how timing and failure status roll up to group rows.

Relevant files:

  • packages/browser/src/client/tester/context.ts
  • test/browser/fixtures/trace/mark.test.ts

Artifact Lifecycle and Transport

How trace-view artifacts should be retained, stored, and transported once traces become larger or more policy-sensitive.

ℹ️ Add a trace-view retention policy

Current MVP behavior:

  • browser.traceView records and reports trace-view artifacts according to its enabled mode.
  • It does not yet model Playwright-style retention policies such as retain-on-failure.

Why this is post-MVP:

  • Retention policy is a product/API decision.
  • The MVP focuses on making trace collection and replay useful first.
  • Retention changes affect artifact lifecycle, reporter behavior, and possibly storage/memory strategy.

Possible direction:

  • Add retention modes for trace-view artifacts.
  • Consider parity or deliberate difference from browser.trace.
  • Decide how retries/repeats interact with retention.

Relevant files:

  • packages/browser/src/client/tester/runner.ts
ℹ️ Reduce memory pressure from snapshot accumulation

Current MVP behavior:

  • Trace entries and DOM snapshots accumulate in browser memory until the current attempt finishes.
  • The full trace artifact is sent at attempt end.

Why this is post-MVP:

  • The current approach is simple and reliable for MVP-sized traces.
  • Reducing payload pressure would touch the collector, browser command transport, artifact shape, and reporter assumptions.
  • This is separate from the viewer-UX goal of showing a live/in-progress trace stream during watch mode.

Possible direction:

  • Flush entries incrementally and clear local snapshot data after acknowledgement if payload size becomes a problem.
  • Store trace artifacts as files/attachments instead of large inline artifact payloads if payload size becomes a problem.
  • Add stress tests for long tests and large snapshots before changing transport.

Relevant files:

  • packages/browser/src/client/tester/trace.ts
  • packages/runner/src/types/tasks.ts

Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. added theissue type on Apr 21, 2026
  2. added
    feat: browser
    on Apr 27, 2026
  3. hi-ogawa commented on Apr 28, 2026

    @hi-ogawa
    CollaboratorAuthor

    More items go here:

    • ℹ️ Snapshot tester iframe document from orchestrator runtime
      • this is to reduce rrweb-snapshot repeatitively for each test file.
    with trivial test, trace view adds +25ms
    • without traceView
    ~/code/others/vitest-wt1 $ pnpm -C test/ui test-fixtures --root fixtures/trace  --run repro --ui=false --brows
    er.traceView.enabled=false
    $ vitest --root fixtures/trace --run repro --ui=false --browser.traceView.enabled=false
    
     RUN  v5.0.0-beta.3 /home/hiroshi/code/others/vitest-wt1/test/ui/fixtures/trace
    
     ✓  chromium  repro.test.ts (1 test) 2ms
       ✓ repro 1ms
    
     Test Files  1 passed (1)
          Tests  1 passed (1)
       Start at  15:40:31
       Duration  548ms (transform 0ms, setup 0ms, import 6ms, tests 2ms, environment 0ms)
    
    • with traceView
    ~/code/others/vitest-wt1 $ pnpm -C test/ui test-fixtures --root fixtures/trace  --run repro --ui=false --browser.traceView.enabled
    $ vitest --root fixtures/trace --run repro --ui=false --browser.traceView.enabled
     Vitest  --browser.traceView is enabled without the HTML reporter.
    
     RUN  v5.0.0-beta.3 /home/hiroshi/code/others/vitest-wt1/test/ui/fixtures/trace
    
     ✓  chromium  repro.test.ts (1 test) 27ms
       ✓ repro 26ms
    
     Test Files  1 passed (1)
          Tests  1 passed (1)
       Start at  15:40:41
       Duration  560ms (transform 0ms, setup 0ms, import 5ms, tests 27ms, environment 0ms)
    
  4. hi-ogawa commented on Apr 29, 2026

    @hi-ogawa
    CollaboratorAuthor

    ℹ️ Snapshot and highlight multiply resolved selector nodes

    Trace snapshots currently resolve a locator to a single mirror ID, so ambiguous selectors can only highlight one element or fail to provide useful visual context. Since trace data is diagnostic rather than part of runtime locator strictness, collection could use querySelectorAll to record all matching mirror IDs, keep selectorId as a compatibility fallback, and add selectorIds for the viewer to highlight every matched element. This would make failed or ambiguous locator traces easier to inspect without changing action/expect behavior.

    Details

    Right now trace is using:

    engine.querySelector(..., false)

    So the snapshot can record only one selectorId. That is fine for action/expect paths where a locator should generally resolve to one element, but trace visualization is diagnostic. If a locator is ambiguous, showing all matched nodes is more useful than recording "missing" or only one target.

    A clean model would be:

    selectorIds?: number[]
    selectorResolution?: 'matched' | 'multiple' | 'missing' | 'error'

    or keep "matched" and infer multiplicity from selectorIds.length > 1. I’d prefer an explicit resolution state if tests/UI will care:

    export type BrowserTraceSelectorResolution =
      | 'matched'
      | 'multiple'
      | 'missing'
      | 'error'

    Then trace collection can do:

    const elements = engine.querySelectorAll(
      engine.parseSelector(serializedLocator._pwSelector ?? serializedLocator.selector),
      document.documentElement,
    )
    
    const ids = elements
      .map(el => mirror.getId(el))
      .filter(id => id !== -1)
    
    if (!ids.length) {
      result.selectorResolution = 'missing'
    }
    else {
      result.selectorIds = ids
      result.selectorId = ids[0] // optional backwards compatibility
      result.selectorResolution = ids.length === 1 ? 'matched' : 'multiple'
    }

    The compatibility question matters. Existing viewer code may only know selectorId, so keeping selectorId = ids[0] while adding selectorIds is a low-risk migration. Later UI can draw multiple highlights.

    One important caveat: this should not replace strict runtime behavior. Actions should still fail on ambiguous locators if that is their contract. Trace can be more permissive because it is debugging state, not performing the user action.

    This also helps provider mismatch cases: if the provider says “too many matches” or fails to pick one, trace can still show exactly what Vitest’s semantic selector matched in the DOM snapshot. That would make failure traces much more actionable.

  5. hi-ogawa commented on May 10, 2026

    @hi-ogawa
    CollaboratorAuthor
    ℹ️ Display aria tree snapshot

    Trace view currently centers on DOM replay snapshots. Add an Aria view so a selected trace step can also show the accessible tree for that moment.

    This is a natural extension of existing browser diagnostics:

    • aria snapshot matchers already show accessible-tree diffs
    • locator-not-found errors can already include an ARIA tree: section
    • role-based locators and accessibility-related assertions make aria semantics part of normal browser-test debugging

    The value is not primarily that aria snapshots are cheaper than DOM replay. They may or may not be. The value is that they answer a different question:

    • DOM replay: what did the page look like?
    • Aria snapshot: what was the user-facing accessible structure?

    Proposal

    Add an Aria diagnostic view alongside Replay for selected trace steps.

    Current trace view is a two-pane UI: the left pane lists steps with metadata, and the right pane shows DOM replay for the selected step. Aria view could extend the right pane with multiple views:

    • Replay
    • Aria

    The simplest version does not need to record a separate aria snapshot. If a DOM replay snapshot exists, the UI can rebuild it into the iframe and derive the aria tree from that reconstructed DOM. This shifts aria generation to view time and avoids extra trace payload.

    If no DOM snapshot is available, the Aria view can explain that accessible-tree data is unavailable for the selected step.

    Capture Options

    There are two possible models:

    1. Derive aria tree from DOM replay snapshot at view time.

      • No extra recording cost or trace payload.
      • Only works when a DOM snapshot exists.
      • Good initial fit if failure-gated DOM snapshots are the primary capture mechanism.
      • Expected to match ordinary DOM, inline/inlined stylesheet state, open shadow DOM, slots, form values, checked state, and selected options because these are already represented in rrweb snapshots/rebuild.
      • Known limits are narrower: intentionally masked inputs, DOM properties rrweb does not serialize such as checkbox indeterminate, closed shadow roots, runtime component state not reflected into DOM/attributes, and CSS effects from pseudo states outside the set Vitest preserves for trace replay.
    2. Capture aria snapshots during test execution.

      • Works even when no DOM replay snapshot is captured.
      • Needs its own capture policy and cost measurement.
      • Useful if aria diagnostics should exist for metadata-only steps.

    If captured aria snapshots become necessary, keep DOM replay snapshots and aria snapshots independent:

    browser: {
      traceView: {
        snapshots: 'always' | 'on-failure' | 'never',
        ariaSnapshot: 'always' | 'on-failure' | 'never',
      },
    }

    This starts with a flat config shape and avoids nested typing/migration questions.

    Possible initial/default direction:

    • DOM snapshot: on-failure
    • Aria view: derived from DOM snapshot initially
    • Captured aria snapshot: future option, possibly on-failure or always
    • Metadata: always

    The important part is not to assume DOM and aria snapshots have the same cost or diagnostic value.

    Relationship To Failure-Gated DOM Snapshots

    This is complementary to failure-gated DOM snapshots. DOM replay can be reserved for failure points, while an Aria view derived from those snapshots provides another diagnostic surface for locator/assertion failures without adding recording-time work.

    Longer term, trace view can be treated as a step timeline plus pluggable captures:

    • DOM replay snapshot
    • aria view derived from DOM replay
    • captured aria snapshot
    • screenshot or visual state
    • future assertion-specific diagnostics

    Suggested Initial Scope

    • reuse the existing ivya/aria capture/render path
    • derive aria tree from the selected DOM replay snapshot at view time
    • add an Aria view for selected trace entries with DOM snapshots
    • defer captured aria snapshots and ariaSnapshot config until there is a clear need
    References and open questions

    References:

    Notes:

    • Aria generation from rebuilt DOM snapshot should be close enough for trace diagnostics in the common path. rrweb snapshots preserve form value/checked/selected state and open shadow DOM/slot structure; Vitest additionally patches rrweb's replay CSS handling for user-action pseudo states beyond upstream :hover.
    • What is the actual cost of aria snapshot capture compared to DOM replay snapshot capture?
    • Should captured aria snapshots exist later for metadata-only steps without DOM snapshots?
    • How should the UI render large aria trees without becoming noisy?
  6. hi-ogawa commented on May 13, 2026

    @hi-ogawa
    CollaboratorAuthor
  7. AriPerkkio commented on May 13, 2026

    @AriPerkkio
    Member

    Currently trace view does not capture contents of iframes. In order to do this, we would need to execute rrweb-snapshot and CSS pseudo-state selector query inside the iframe context.

    Accessing iframe context requires server side Playwright page.frames() + frame.evaluate() APIs. As Vitest currently operates DOM snapshot capturing on client side context, this would require additional client->server->client calls. So something like:

    Reference implementation:

  8. AriPerkkio commented on May 15, 2026

    @AriPerkkio
    Member

    Improve how nested marks are shown 💡

    When actions that produce marks are nested, trace view should indicate this nesting. It should probably collapse all child marks inside the parent one by default. When clicking the parent mark, child marks are shown with some indentation.

    This is what is currently shown. It's not clear that tab contains both click and tab:

    Image
  9. sheremet-va commented on May 23, 2026

    @sheremet-va
    Member

    Two questions:

    • can we inject the link to preview report online in the github summary automatically if trace view is generated?
    • do we still import rrweb inside the iframe and not in the orchestrator? If so, is it even possible to do?
  10. hi-ogawa commented on May 25, 2026

    @hi-ogawa
    CollaboratorAuthor
    • can we inject the link to preview report online in the github summary automatically if trace view is generated?

    The questions is unclear. Auto linking directly between github reporter and html reporter artifact URL sounds difficult because artifact URL can be known only after actions/upload-artifact step.

    • do we still import rrweb inside the iframe and not in the orchestrator? If so, is it even possible to do?

    Untested but it's possible in my mind. This is tracked in #10156 (comment).

  11. beanscg commented on Jun 10, 2026

    @beanscg
  12. hi-ogawa commented on Oct 7, 2026

    @hi-ogawa
    CollaboratorAuthor

    Status update before closing this issue. Each remaining item is now either tracked in its own issue or PR, or deferred without tracking.

    Done

    • Live trace updates in watch mode (#10296)
    • Nested marks (#10437) and editor gutter markers (#10404)
    • Keyboard step navigation (#11005), URL-persisted selection (#10981), and focused layout=trace mode (#11190)
    • Highlight toggle (#11049), multi-match highlight (#11489), and fit and zoom (#11490)
    • Popover state (#11021) and loading rrweb once per worker in the orchestrator (#10984)
    • Aria tree view (PR ready) (#11492)

    Tracked separately

    • Failure-only snapshot capture: #10310
    • Agent-facing trace inspection: #10634
    • Trace view outside browser mode: #11045
    • Upstream rrweb-snapshot patch: #10688

    Deferred, not tracked

    These can get their own issue when a concrete need comes up.

    Not planned

  13. locked and limited conversation to collaborators on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    feat: browser

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions