Skip to content

Playwright - add java sources to a captured Playwright trace - #1450

Merged
andrcuns merged 3 commits into
allure-framework:mainfrom
antonfilichkin:feat/playwright-trace-sources-flag
Nov 13, 2026
Merged

andrcuns merged 3 commits into
allure-framework:mainfrom
antonfilichkin:feat/playwright-trace-sources-flag

Conversation

@antonfilichkin

@antonfilichkin antonfilichkin commented Sep 21, 2026 •

Copy link
Copy Markdown
Contributor

Context

Closes #1452

Allows attaching java sources to Playwright traces.

Allure only configures Playwright traces to include screenshots and snapshots via

new Tracing.StartOptions()
    .setScreenshots(true)
    .setSnapshots(true)

Playwright allows including java sources by setting PLAYWRIGHT_JAVA_SRC and configuring tracing via

new Tracing.StartOptions()
    .setSources(true)

The problem:

  1. Playwright provides trace as .zip binary
  2. Playwright doesn't have mechanism to suppress synthetic frames from trace, it only handles its own ones. But with Allure enabled - frame 0 is always synthetic AspectJ-weaving glue inserted by AllurePlaywrightAspect, not the real caller - making Trace Viewer's Source tab useless.
  3. Playwright handles trace building on it's binary side

The idea is to add configurable option to allow Allure rewrite sources and remove it's own synthetic frames
Implementation idea:

  • Add allure.playwright.trace.sources (default false) to opt into embedding sources in the trace.
  • Add TraceStackSourceTrimmer, which rewrites the trace.stacks entry in place: it resolves the first file-backed frame in each stack, falling back to stripping the leading run of recognizable AspectJ/Playwright weaving frames when no frame resolves. Fails open on any error, leaving the trace attached unchanged. With some short-circuits to disable zip/json processing - I.e. binary blobs, sources path not set.

Trace examples (both with sources)
Screenshot 2026-09-21 at 12 07 30
npx playwright show-trace trace-after.zip
trace-before.zip
trace-after.zip

Checklist

@baev
baev requested review from a team and andrcuns and removed request for a team November 2, 2026 17:19

@andrcuns andrcuns left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for the submission @antonfilichkin

My java is very rusty (almost non existent at this point 😅 ) but an agent review found a few issues, could you please check?

@andrcuns andrcuns added the pr:improvement Change that improves some user experience but can't be considered as a new feature label Nov 4, 2026
@antonfilichkin
antonfilichkin force-pushed the feat/playwright-trace-sources-flag branch from 0461ca9 to ffc9e1b Compare November 6, 2026 06:30
@andrcuns

andrcuns commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

@antonfilichkin Could you please take a look at failing test?

@andrcuns
andrcuns self-requested a review November 12, 2026 13:06
…spectJ frames from trace stacks

Playwright's Tracing.StartOptions#setSources embeds a stack per action, but
frame 0 is always synthetic AspectJ-weaving glue inserted by
AllurePlaywrightAspect, not the real caller - making Trace Viewer's Source
tab useless without this.

- Add allure.playwright.trace.sources (default false) to opt into embedding
  sources in the trace.
- Add TraceStackSourceTrimmer, which rewrites the trace.stacks entry in
  place: it resolves the first file-backed frame in each stack, falling
  back to stripping the leading run of recognizable AspectJ/Playwright
  weaving frames when no frame resolves. Fails open on any error, leaving
  the trace attached unchanged.
- Declare the module's new compile-time-only dependency on Gson in
  module-info.java.
- Don't require PLAYWRIGHT_JAVA_SRC in the process environment: Playwright
  also accepts it per instance via CreateOptions.setEnv(), so the
  allure.playwright.trace.sources property alone now enables sources.
- Rewrite only trace.stacks via the JDK zip filesystem; all other entries
  are copied with their original compressed payloads instead of being
  fully buffered in memory and re-written as STORED.
- Cover per-instance configuration through AllurePlaywright.startTracing()
  and check that unchanged entries keep their compression.
… name

Playwright 1.64 stores trace sources as src/<sha1>.java instead of
resources/src@<sha1>.txt.
@andrcuns
andrcuns force-pushed the feat/playwright-trace-sources-flag branch from 4ce6bf3 to b47ac9b Compare November 12, 2026 13:06
@andrcuns
andrcuns merged commit fb1867e into allure-framework:main Nov 13, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr:improvement Change that improves some user experience but can't be considered as a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Playwright: support embedding Java sources in captured traces

2 participants