diff --git a/.changeset/hosted-player-parse-in-worker.md b/.changeset/hosted-player-parse-in-worker.md new file mode 100644 index 000000000..a0424d9b4 --- /dev/null +++ b/.changeset/hosted-player-parse-in-worker.md @@ -0,0 +1,5 @@ +--- +'@wdio/devtools-app': patch +--- + +The hosted trace player reads a trace `.zip` in a Web Worker instead of on the page's main thread, so the tab no longer freezes while a large trace opens. While it works, the landing screen names the step it is on (reading the file, unpacking the archive, building the timeline) under a progress bar that does not claim a percentage. The worker loads from the player's own origin, within the existing content security policy. The live dashboard is unchanged. diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md index 8b143269d..dbb41c9ce 100644 --- a/ARCHITECTURE.md +++ b/ARCHITECTURE.md @@ -67,7 +67,7 @@ Contains: - `buildImageFrameSnapshots` + `buildScreenshotResourceSnapshots` / `upsertRichestSnapshot` / `buildDenseScreencast` / `thinScreencastFrames` — filmstrip and per-action frame snapshots (each a page whose image is the stored screenshot, reached through a `resourceOverrides` entry and the one recorded response it patches). - `buildMutationsNdjson` / `reattributeDomAnchors` — the DOM mutation stream and its anchor repositioning. - `buildConsoleEvents`, `networkRequestToHar`, `buildSourceResources` / `sourceResourceName` / `callSourceToStack`, `generateTranscript`, `sha1Hex`. -- `parseTraceZip` (`trace-reader.ts` and its `trace-reader-*` siblings) — the reverse direction: a `trace.zip`, ours or a foreign one, back into the `TracePlayerData` the player renders. Imported by subpath (`@wdio/devtools-trace/trace-reader`) and kept out of the package index, so adapters that reach `trace` through `core` never inline it. It reaches no Node built-in, because the hosted player runs it in the browser (`tests/trace-reader-browser-safe.test.ts` walks its imports); the disk read is `readTraceZip` in `read-trace-zip.ts`, and source paths are hashed with the pure `portableSha1Hex` so the reader needs no `node:crypto`; resource bytes keep native `sha1Hex`, ~30x faster. +- `parseTraceZip` (`trace-reader.ts` and its `trace-reader-*` siblings) — the reverse direction: a `trace.zip`, ours or a foreign one, back into the `TracePlayerData` the player renders. Imported by subpath (`@wdio/devtools-trace/trace-reader`) and kept out of the package index, so adapters that reach `trace` through `core` never inline it. `parseTraceZip` is `unzipTraceZip` then `parseTraceEntries`, exported separately so the hosted player can report each as a phase. It reaches no Node built-in, because the hosted player runs it in the browser, in a Web Worker (`tests/trace-reader-browser-safe.test.ts` walks its imports); the disk read is `readTraceZip` in `read-trace-zip.ts`, and source paths are hashed with the pure `portableSha1Hex` so the reader needs no `node:crypto`; resource bytes keep native `sha1Hex`, ~30x faster. Imports from: `shared`. Imported by: `core` (which re-exports it, so adapters reach it unchanged), `backend`, and `app`, which may import `trace-reader` alone (ESLint enforces it). diff --git a/CLAUDE.md b/CLAUDE.md index 0c706e351..f4a132a5c 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -104,7 +104,7 @@ They import from `shared` and `core`, never from each other. They aren't importe ### Backend and app are framework-agnostic -`backend` and `app` import from `shared` (for contracts) and from each other via the WS/HTTP boundary. Neither imports an adapter package. `backend` also imports `trace`, to write and read zips; `app` imports only `trace`'s reader, which the hosted player (`trace.webdriver.io`, built with `pnpm player:hosted`, deployed by Vercel from `vercel.json`) runs in the browser to open a dropped zip with no backend at all. That build is `HOSTED_PLAYER` in `app/src/controller/constants.ts`; it never writes the trace to browser storage, and `vercel.json` is also what `vite preview` serves, so its CSP is checked locally before it ships. +`backend` and `app` import from `shared` (for contracts) and from each other via the WS/HTTP boundary. Neither imports an adapter package. `backend` also imports `trace`, to write and read zips; `app` imports only `trace`'s reader, which the hosted player (`trace.webdriver.io`, built with `pnpm player:hosted`, deployed by Vercel from `vercel.json`) runs in the browser to open a dropped zip with no backend at all. It runs the reader in a module Web Worker loaded from the player's own origin (`app/src/controller/trace-parse.worker.ts`, which `script-src 'self'` already admits), so the tab stays responsive and the landing screen names the phase the open is on; the live build never references the worker. That build is `HOSTED_PLAYER` in `app/src/controller/constants.ts`; it never writes the trace to browser storage, and `vercel.json` is also what `vite preview` serves, so its CSP is checked locally before it ships. Framework-specific behavior in the backend is contained in two files: `runner.ts` and `framework-filters.ts`. Both branch on a typed `TestRunnerId` from shared, never on a magic string. The `framework-filters` dispatch is a `switch` over `TestRunnerId` (not a table lookup) so CodeQL's `unvalidated-dynamic-method-call` query trusts the call site. diff --git a/packages/app/src/app.ts b/packages/app/src/app.ts index 57392430c..318f1bbc6 100644 --- a/packages/app/src/app.ts +++ b/packages/app/src/app.ts @@ -41,8 +41,8 @@ onThemeChange(applyDarkMode) export class WebdriverIODevtoolsApplication extends Element { dataManager = new DataManagerController(this) #traceOpen = HOSTED_PLAYER - ? new TraceOpenController(this, (file) => - this.dataManager.openTraceArchive(file) + ? new TraceOpenController(this, (file, onPhase) => + this.dataManager.openTraceArchive(file, onPhase) ) : undefined @@ -256,6 +256,7 @@ export class WebdriverIODevtoolsApplication extends Element { if (traceOpen && (traceOpen.opening || !this.dataManager.hasConnection)) { return html`` } diff --git a/packages/app/src/components/onboarding/open-trace.ts b/packages/app/src/components/onboarding/open-trace.ts index c8afd0ec0..44468bbe7 100644 --- a/packages/app/src/components/onboarding/open-trace.ts +++ b/packages/app/src/components/onboarding/open-trace.ts @@ -2,13 +2,18 @@ import { Element } from '@core/element' import { html, css, nothing } from 'lit' import { customElement, property, query, state } from 'lit/decorators.js' -import { TRACE_FILE_ACCEPT } from '../../controller/constants.js' +import { + TRACE_FILE_ACCEPT, + TRACE_OPEN_PHASE_LABEL +} from '../../controller/constants.js' +import type { TraceOpenPhase } from '../../controller/trace-parse-protocol.js' import { announceTraceFile, takePickedFile } from '../../utils/trace-file.js' /** Landing screen of the hosted trace player: pick or drop a trace.zip. */ @customElement('wdio-devtools-open-trace') export class DevtoolsOpenTrace extends Element { @property({ type: Boolean }) busy = false + @property() phase?: TraceOpenPhase @property() error?: string @state() dragging = false @@ -61,6 +66,41 @@ export class DevtoolsOpenTrace extends Element { cursor: progress; } + /* Indeterminate: the reader cannot say how far through a step it is. */ + .progress { + height: 3px; + margin-top: 12px; + overflow: hidden; + border-radius: 2px; + background: var(--vscode-panel-border); + } + + .progress::after { + content: ''; + display: block; + width: 40%; + height: 100%; + background: var(--accent); + animation: progress-slide 1.2s ease-in-out infinite; + } + + @keyframes progress-slide { + from { + transform: translateX(-100%); + } + to { + transform: translateX(250%); + } + } + + @media (prefers-reduced-motion: reduce) { + .progress::after { + width: 100%; + animation: none; + opacity: 0.5; + } + } + .error { color: var(--vscode-charts-red); } @@ -106,6 +146,13 @@ export class DevtoolsOpenTrace extends Element { this.#open(takePickedFile(this.input)) } + #status(): string { + if (!this.busy) { + return 'Drop a trace.zip here' + } + return this.phase ? TRACE_OPEN_PHASE_LABEL[this.phase] : 'Opening trace…' + } + render() { return html`

WebdriverIO Trace Viewer

-

- ${this.busy ? 'Opening trace…' : 'Drop a trace.zip here'} -

+

${this.#status()}

+ ${this.busy ? html`
` : nothing}