Skip to content

Parse the hosted player's trace in a Web Worker - #514

Merged
vishnuv688 merged 1 commit into
mainfrom
perf/497-parse-in-worker
Nov 2, 2026
Merged

vishnuv688 merged 1 commit into
mainfrom
perf/497-parse-in-worker

Conversation

@vishnuv688

Copy link
Copy Markdown
Member

What & why

Closes #497. Part of #494. Stacked on #513.

The hosted player unpacked and parsed the zip on the main thread, so the tab froze for the whole read and the landing screen could only say "Opening trace…". The parse now runs in a Web Worker, and the landing screen names the step it is on: reading the file, unpacking the archive, building the timeline.

Type of change

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Polish (an improvement to an existing feature)
  • Breaking change (existing behavior changes for users)
  • Documentation
  • Internal (build, CI, dependencies, tooling)

Packages touched

  • shared (types and contracts)
  • core (framework-agnostic capture/reporting)
  • elements (published element/snapshot API — @wdio/elements)
  • service (WebdriverIO adapter)
  • nightwatch-devtools (Nightwatch adapter)
  • selenium-devtools (Selenium adapter)
  • selenium-devtools-py (Selenium Python adapter)
  • backend (server)
  • app (UI)
  • script (page-injected runtime)
  • trace (Trace mode)

Capability matrix

  • packages/conformance/src/features.ts updated, and tables regenerated with pnpm docs:capabilities, if this adds or changes user-facing behaviour

Not needed: hosted player only, not per-adapter.

Notes for reviewers

Design notes

  • The worker is new Worker(new URL('./trace-parse.worker.ts', import.meta.url), { type: 'module' }), emitted as a hashed file under /assets/ and loaded from the player's own origin. The CSP sets no worker-src, so it falls back to script-src 'self', which already allows it; vercel.json is unchanged.
  • The zip's bytes are transferred to the worker, not copied.
  • The worker is a four-line wrapper around answerParseRequest, which the no-Worker path (vitest's happy-dom has no Worker) runs in the page, so the tests exercise the code the worker runs.
  • Errors read as before: Not a readable trace: <reason> and No trace found in this archive. A worker that fails to load rejects the open ("The trace reader could not start") rather than falling back silently, so a CSP break would be visible.
  • Progress is three named phases with an indeterminate bar, which stays still under reduced motion. No percentage: fflate's unzipSync cannot report one.
  • parseTraceZip in trace is split into unzipTraceZip and parseTraceEntries so the worker can report the step between them; parseTraceZip composes the two and behaves as before.
  • Not faster overall: the same parse runs off the main thread, so the tab stays responsive. The result is copied back to the page.

Bundles

Build Worker Main bundle
Hosted trace-parse.worker-*.js, 21 KB, created by the page index-*.js
Live The same file is emitted (Vite writes it before dead code is removed) but nothing references it: 0 new Worker in dist/ index-*.js

Testing

  • pnpm build, pnpm test (3313 passed) and pnpm lint are green.
  • New tests: the worker's handler for a real zip and for junk; parseInWorker against a fake Worker (URL, module type, bytes transferred, worker terminated, a worker that fails to start); phase order and error wording from readTraceArchive; the split reader functions give the same result as parseTraceZip. The existing hosted tests pass unchanged.

Not verified yet (needs a browser, in pnpm player:hosted)

  1. Drop a large trace: the three phases show, the bar slides, the page stays responsive, the Network tab shows /assets/trace-parse.worker-*.js, and the console shows no CSP violation.
  2. Drop a non-zip and a zip with no trace: the errors above appear.
  3. With a trace loaded, drop a bad file: the banner appears and the trace stays.
  4. With reduced motion on, the bar is still.
  5. In the live dashboard (pnpm demo:wdio), no worker file is requested.

Screenshots / recordings

To be added: the landing screen during each phase.

🤖 Generated with Claude Code

The hosted player unpacked and parsed the zip on the main thread, so the tab
froze for the whole read, and "Opening trace…" was all it could say. The
parse now runs in a module worker loaded from the player's own origin, which
the CSP already allows through script-src 'self', and the landing screen
names the step it is on: reading the file, unpacking, building the
timeline. There is no percentage, since none of the steps can report one.

The worker and the no-Worker fallback run the same handler, so the tests
exercise the code the worker runs. A worker that fails to start rejects the
open rather than falling back silently, so a CSP break is visible.

Closes #497

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@vishnuv688
vishnuv688 force-pushed the fix/505-screenshot-extension branch from 7a751ea to 730a86d Compare October 30, 2026 10:12
@vishnuv688
vishnuv688 force-pushed the perf/497-parse-in-worker branch from 6bfa403 to 938e36a Compare October 30, 2026 10:12
@vishnuv688
vishnuv688 changed the base branch from fix/505-screenshot-extension to main November 2, 2026 09:21
@vishnuv688
vishnuv688 merged commit 5d4b9a4 into main Nov 2, 2026
7 checks passed
@vishnuv688
vishnuv688 deleted the perf/497-parse-in-worker branch November 2, 2026 09:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Hosted player: parse the trace in a Web Worker, with progress

1 participant