Browser Engine / Playwright Integration Spec

Status

Validated via spec interview on April 25, 2026. This spec supersedes the browser engine sections of specs/agent-native-browser-qa-platform.md for v1 implementation.

Summary

Automium v1 uses Playwright on Chromium as the browser execution substrate instead of building a custom browser engine. Automium's differentiator — semantic state graphs, stable element identity, deterministic execution, causal replay, and model benchmarking — is built as an enrichment layer on top of Playwright's accessibility tree and Chrome DevTools Protocol.

A thin BrowserRuntime abstraction boundary keeps the custom engine option open for v2+ without coupling Automium code to Playwright directly.

Each journey run executes in an ephemeral Firecracker microVM with a cold-booted Chromium instance for maximum determinism and isolation.

Strategic Rationale

The original spec committed to building a new browser engine from scratch. This interview validated a different approach:

Architecture

Layer Model

┌─────────────────────────────────────────┐
│           Planner Layer                 │
│   (GPT / Claude / Gemini adapters)      │
├─────────────────────────────────────────┤
│        Deterministic Executor           │
│   (intent → BrowserRuntime actions)     │
├─────────────────────────────────────────┤
│       Semantic Runtime Layer            │
│   (enriched snapshots, stable IDs,      │
│    actionability, mutation diffs,        │
│    vision triggers)                     │
├─────────────────────────────────────────┤
│       BrowserRuntime Interface          │
│   (navigate, snapshot, execute,         │
│    capture, observe)                    │
├─────────────────────────────────────────┤
│       Playwright Adapter                │
│   (Locator API + CDP subscriptions)     │
├─────────────────────────────────────────┤
│       Chromium (headless shell)         │
├─────────────────────────────────────────┤
│       Firecracker microVM               │
└─────────────────────────────────────────┘

BrowserRuntime Interface

A thin adapter with approximately 5-8 methods. Automium code never imports Playwright directly — only the adapter.

Required methods:

The interface is intentionally narrow. Features like cookie manipulation, storage access, or JS evaluation are exposed only if a planner intent requires them, not as general-purpose engine access.

Playwright Adapter Implementation

The adapter implements BrowserRuntime using:

Semantic Runtime Layer

Built on top of the BrowserRuntime interface, the semantic layer enriches Playwright's raw accessibility tree into the agent-native snapshot contract.

Enrichment Pipeline

  1. Raw snapshot: Call snapshot() to get Playwright's accessibility tree (roles, names, refs).
  2. Stable ID assignment: Assign persistent element IDs using DOM attribute + position + role heuristics. IDs survive rerenders as long as the element's semantic identity is preserved.
  3. Actionability scoring: Derive per-element actionability scores from Playwright's actionability checks (visible, enabled, stable, not obscured) combined with semantic role and ARIA state.
  4. Mutation diffing: Compare current snapshot against previous snapshot. Tag elements as added, removed, or changed. Correlate with CDP DOM mutation events for timing precision.
  5. Network correlation: Attach relevant network events (API responses, errors) to the snapshot context for the current step.
  6. Frame flattening: Elements from all frames (including iframes) are included in a single unified element list, tagged with frame origin and nesting depth. The planner sees one flat list and does not need to manage frame boundaries. Frame metadata is preserved for replay and cross-origin security checks.
  7. Vision trigger evaluation: Apply runtime heuristics to flag ambiguity:

Attach vision_recommended: true with candidate element refs. Budget-capped: max 2-3 crops per step, each under 100 KB.

Semantic Snapshot Output

Each planner step receives the enriched snapshot containing:

Sandboxing Model

Isolation Unit

One Firecracker microVM per journey run.

Why Firecracker

Target Scope Constraint

v1 supports only owned or consented properties:

Domain allowlist is mandatory and enforced at the policy layer before the BrowserRuntime receives a navigation URL. This constraint reduces the browser security threat model significantly — the sandboxed Chromium only loads known, authorized applications.

Executor Integration

Action Compilation

The deterministic executor compiles planner intents into BrowserRuntime method calls:

Planner Intent BrowserRuntime Action
navigatenavigate(url)
clickexecuteAction({ type: 'click', target: elementRef })
type/fillexecuteAction({ type: 'fill', target: elementRef, value })
selectexecuteAction({ type: 'select', target: elementRef, value })
uploadexecuteAction({ type: 'upload', target: elementRef, files })
press-keyexecuteAction({ type: 'pressKey', key })
wait-for-conditionexecuteAction({ type: 'waitFor', condition })
assertEvaluated against semantic snapshot (no browser action)
extractRead from semantic snapshot or executeAction({ type: 'extract', target })
branchControl flow (no browser action)
recoverRe-snapshot + retry or alternate path
finishclose() + artifact collection

The executor uses Playwright's Locator API under the hood, which provides auto-waiting and actionability checks. The executor adds:

Vision Capture Flow

  1. Semantic runtime flags vision_recommended with candidate element refs
  2. Executor checks vision budget (max crops per step)
  3. Executor calls captureElementScreenshot(elementRef) via BrowserRuntime
  4. Screenshot artifact is annotated with semantic context (role, label, nearby elements, bounding box, timestamp)
  5. Annotated crop is included in the planner's next prompt
  6. Crop is also stored as a replay artifact regardless of whether it was sent to the planner

Authentication Model

Credentials are resolved from a scoped vault (per-tenant, per-environment) and injected into the Firecracker microVM at boot time as environment variables or a mounted secrets file.

This model ensures that:

Network Observation

Application-level traffic only:

This keeps the network trace focused on QA-relevant data (API responses, error codes, data payloads) and reduces artifact size. Static asset failures surface as exceptions rather than noise.

Trace and Replay Artifacts

Primary: Automium Event Stream

The custom replay event stream is the primary artifact for causal debugging:

Supplementary: Playwright Trace

Playwright's trace.zip is captured for each run as a supplementary artifact:

The Playwright trace is available for deep debugging (CSS/layout issues, timing problems) but is not the primary interface for failure diagnosis. The Automium replay console consumes the Automium event stream; the Playwright trace viewer can be opened separately when needed.

Browser Engine Scope

v1: Chromium Only

v2+: Multi-Browser

v2+ Strategic Option: Custom Engine

The BrowserRuntime interface is designed so a custom engine implementation can replace the Playwright adapter without changing any Automium code above the interface. This preserves the original spec's strategic vision while removing it from the critical path for v1.

A custom engine becomes justified when:

Performance Targets

Metric Target Rationale
Cold start (VM + Chromium + first navigation)<5 secondsAcceptable for QA workloads. Achievable with Firecracker + pre-built Chromium image.
Semantic snapshot generation<200ms per stepEnrichment pipeline on a11y tree should be fast; most cost is in the Playwright snapshot call.
Journey step execution<2 seconds medianExcluding network wait (target app response time). Playwright Locator API is fast.
Full journey (10-step login + CRUD)<30 seconds medianCovers real SaaS workflow with login, navigation, form fills, assertions.
Targeted vision capture<500ms per cropPlaywright element screenshot is fast; annotation adds minimal overhead.

Revised Phased Build Plan

The original spec's Phase 1 (custom engine construction) is replaced:

Phase 1: BrowserRuntime Adapter + Enriched Snapshots

Deliverables:

  1. BrowserRuntime interface definition (~5-8 methods)
  2. Playwright adapter implementing the interface
  3. Semantic snapshot enrichment layer (stable IDs, actionability scores, mutation diffs)
  4. CDP observation pipeline (network, console, DOM mutations)
  5. Targeted vision capture via Playwright screenshots
  6. Basic Firecracker microVM image with Chromium + Playwright pre-installed

Exit criteria:

Subsequent Phases

Phases 2-5 from the original spec (executor runtime, vision/compaction, control plane, replay console) proceed as designed, now targeting the Playwright-backed BrowserRuntime instead of a custom engine. The scope of each phase is reduced because Playwright handles HTML/CSS/JS/layout execution.

Compatibility with Existing Contracts

The existing packages/engine/, packages/runtime/, and packages/contracts/ surfaces model browser state, semantic snapshots, and stable element identity at the contract level. The Playwright integration implements these contracts rather than replacing them:

No contract changes are required. The implementation layer beneath the contracts changes from "future custom engine" to "Playwright adapter."

Open Questions