feat: Introduce Vibium-tracing into the WebdriverIO ecosystem #110
Conversation
Adds opt-in trace recording that produces a zip playable at player.vibium.dev. - New `src/trace/` module: types, tool mapping, session state, recorder HOF, zip writer - `withTrace` HOF wraps action tools alongside `withRecording`; captures a JPEG screenshot after each action - `start_session` gains `trace: true` flag to enable recording per session - New `export_trace` MCP tool writes the trace zip to a specified path or temp dir - `src/trace.ts` barrel export mirrors the `snapshot.ts` pattern for future extraction to `@wdio/trace` - 26 new unit tests covering tool mapping, state lifecycle, HOF event emission, and zip structure - The zip is automatically saved to .trace/<timestamp>-<sessionId>.zip relative to the server's cwd
Expands the roadmap with details on mobile trace recording for Appium sessions, including specific goals, advantages, and dependencies. Also outlines plans for WebDriver BiDi-based asynchronous trace recording. Streamlines future development priorities and feature dependencies.
Introduces `src/show-trace.ts`, a Node.js CLI to serve trace zip files via HTTP and open them in the Vibium trace player. Automatically detects the latest trace zip or accepts a path as an argument. Updates `package.json` and `tsup.config.ts` to integrate the tool.
Introduces a detailed documentation file outlining the vision, workflow, and components for trace recording and deterministic replay. Covers `.vibium` spec, `.trace` format, self-healing mechanism, and future considerations.
- Remove hardcoded viewport from trace to match the browserSession - Remove references to non-existent export_trace tool
Greptile SummaryThis PR introduces Vibium-compatible trace recording for both browser and mobile (iOS/Android) WebdriverIO sessions. When a session is started with
Confidence Score: 5/5Safe to merge; the new trace recording path is well-isolated, correctly cleans up session state in all exit branches, and does not affect existing tool execution when tracing is disabled. All three session-close paths correctly pass an explicit browser reference rather than relying on global session state. The tracing infrastructure is opt-in behind a trace flag, so existing sessions are completely unaffected. All findings are non-blocking quality improvements. src/trace/zip-writer.ts (trailing newline), src/show-trace.ts (exec error handling and CORS preflight headers)
|
| Filename | Overview |
|---|---|
| src/trace/recorder.ts | Core tracing wrapper: withTrace instruments tool callbacks with before/after events and pre-action screenshots. Screenshot fallback via getBrowser() is safe in withTrace, and screenshotChain correctly serializes the final screenshot in finalizeTrace. |
| src/trace/zip-writer.ts | Builds Playwright-compatible trace zip; NDJSON events joined without a trailing newline, which may cause the last event to be dropped by line-buffered parsers. |
| src/show-trace.ts | Local dev CLI that serves a trace zip on localhost and opens the Vibium player. exec errors are silently swallowed and the CORS preflight response omits Access-Control-Allow-Headers. |
| src/session/lifecycle.ts | Adds finalizeTrace called in both closeSession and orphaned-session cleanup; both paths correctly pass the explicit browser reference rather than relying on getBrowser(). |
| src/trace/state.ts | Module-level traceSessions Map with create/get/delete helpers; monotonic time via process.hrtime.bigint(). Clean and straightforward. |
| src/trace/tool-mapping.ts | Maps tool names to Playwright trace action classes/methods. The start_session entry is unreachable (flagged in a prior review thread). |
| src/tools/session.tool.ts | Adds trace parameter to start_session; correctly calls startTrace after registerSession and records initial navigation for all three session modes. |
| src/trace/types.ts | Well-typed definitions for all four Playwright-compatible trace event shapes plus TraceSession state. No issues found. |
| src/server.ts | Introduces the instrument helper composing withTrace over withRecording; all mapped tools upgraded consistently. |
Sequence Diagram
sequenceDiagram
participant Client as MCP Client
participant Server as server.ts
participant WTrace as withTrace
participant Tool as Tool Callback
participant TState as TraceSession
participant Browser as WebdriverIO.Browser
Client->>Server: start_session(trace:true)
Server->>Tool: startSessionTool
Tool->>TState: createTraceSession
Tool->>Browser: url(navigationUrl)
Tool->>TState: recordInitialNavigation
loop Each instrumented tool call
Client->>Server: tool call
Server->>WTrace: instrument(name, cb)(params)
WTrace->>Browser: takeScreenshot
WTrace->>TState: push screencast-frame + before
WTrace->>Tool: callback(params, extra)
Tool-->>WTrace: result
WTrace->>TState: push after event
end
Client->>Server: close_session
Server->>Browser: takeScreenshot (final)
Server->>TState: await screenshotChain
Server->>Server: buildTraceZip + writeFileSync
Server->>TState: deleteTraceSession
Reviews (2): Last reviewed commit: "fix(trace): Ensure `finalizeTrace` handl..." | Re-trigger Greptile
- Remove redundant start_session from trace map
Proposed changes
Adds Vibium-compatible trace recording for both browser and mobile (iOS/Android) sessions.
When a session is started with
trace: true, every tool call is captured as a structured trace event: before/after timestamps, action class and method, parameters, and screenshots.Its exported to a .zip file on session close. The zip is playable directly in the Vibium player (player.vibium.dev) with a full action timeline and screenshot filmstrip.
Key design decisions:
Types of changes
Checklist
Further comments
Reviewers: @webdriverio/project-committers