ov.capture.browser#

Playwright facade – the baseline driver (§9, D1).

This hides Playwright behind a clean lifecycle so no caller (or skill, or future agent) ever touches a raw Playwright object. It is treated as a *facade over a CDP escape hatch, not a wall*: BrowserSession.cdp() lazily attaches a CdpSession for the ~20% the high-level API can’t reach.

The sync Playwright API is used deliberately – capture is a synchronous, step-by-step orchestration and the sync API keeps the code legible. HAR is recorded to a temp .har.zip with embedded bodies and read back after the context closes (HAR only flushes on context.close()); structured network records come from event accumulation in the network probe, not from the HAR.

Classes

BrowserSession(config, *[, record_har])

Owns a Playwright browser/context/page for one capture run.

Exceptions

BrowserNotAvailable

Raised when Playwright or its browsers are not usable.

exception ov.capture.browser.BrowserNotAvailable[source]#

Bases: RuntimeError

Raised when Playwright or its browsers are not usable.

Carries the install hint so the message is actionable, per the project’s informative-errors principle.

class ov.capture.browser.BrowserSession(config, *, record_har=True)[source]#

Bases: object

Owns a Playwright browser/context/page for one capture run.

Lifecycle is explicit (start() / close()) so the orchestrator can flush in-memory probe state before closing the context (which flushes HAR), then ingest the HAR. It is also a context manager for simple call sites.

cdp()[source]#

Lazily attach and return a CdpSession (Chromium).

Returns None on non-Chromium browsers, where CDP is unavailable.

close()[source]#

Close the context (flushing HAR), read the HAR, then tear down.

Return type:

None

property context#

The active Playwright BrowserContext.

property har_bytes: bytes | None#

The recorded HAR archive bytes (available only after close()).

property page#

The active Playwright Page (raises if not started).

start()[source]#

Launch the browser and open a context + page. Returns self.

Return type:

BrowserSession

stop()[source]#

Hard teardown of browser + playwright (idempotent).

Return type:

None