Repository navigation
Capture Pipeline
Role. Produce comparable captures: every engine at the same viewport, the page settled to the same state, geometry and screenshot taken at the same moment, written into the bundle. Everything downstream measures differences between captures, so anything that varies here for a reason other than the engine becomes a false finding. Module capture, package internal/capture, with the in-page scripts in assets/inject.
-
In: a
Plan(output dir, viewport, timeouts, run count, engines with their session factories, the baseline, resume flags,NoProbes,AllowSmallPages, the job'sLostset) and one page. -
Out: per engine and run,
<engine>-<run>.json,.pngand.probes.json.gz, or.error.txt;page.json;failed.jsonfor an unreachable page (Data contracts). AnOutcomeper capture goes to the CLI for progress events.
Page first removes any previous attempt's files for this engine and run, so the bundle never holds a capture and an error for the same run. Then (page.go):
-
Viewport.
SetViewportto the job's viewport (1280×800 at DPR 1 by default). -
Navigate, within the navigation timeout (30 s by default), then settle: network idle (500 ms with no request in flight, at most 8 s) where the driver can tell, a fixed 1.5 s on WebDriver Classic (
capture.go). Not reaching idle is not an error: some pages poll forever. -
Stabilize with
stabilize.js: hide the root scrollbar and gutter (Chrome keeps a 15 px gutter forscrollbar-gutter: stableeven with hidden scrollbars), wait fordocument.fonts.ready, scroll in steps to trigger lazy content (a jump to the bottom skips theIntersectionObservercallbacks in the middle), wait for images, jump finite animations to their end and freeze infinite ones at t=0, then freeze JavaScript timers so the geometry and the screenshot describe the same moment. Settle again, at most 5 s. -
Extract with
extract.js: the geometry tree, at most 20,000 nodes (meta.truncatedwhen the cap is hit). The page's DOM is read through the platform's own accessors, never through properties the page can shadow: a<form>exposes its controls as properties (form.idis<input name="id">), and a custom element can redefine anything. Each node records its position among its same-tag siblings (nt), counted over every element child, including thedisplay: noneones the tree leaves out, so a selector's:nth-of-typenames the element the browser would. The children of an open shadow root carrysr, so a selector can name their host instead. -
Evidence (
evidence.go):- the full-page screenshot, capped at 2560×16000 px;
- the painted check (
painted.go, backlog B17): a browser can lay a page out and paint none of it (Safari 27.2 on macOS runner image 20261117.0516.1 drew only shadows and scrollbars). A visible text box (own text, nothid, at least 4×4 px, wholly inside the screenshot) has ink when its pixels span more than 24 levels in some channel; with at least 10 such boxes and fewer than 10% inked, the screenshot is unpainted. A session with element screenshots (drivers.ElementScreenshotter, the Classic driver) then retakes it through element screenshots of<html>and the check runs again; a painted retake becomes the capture's screenshot, withshotNote"the window screenshot held none of the page's text: taken with element screenshots of<html>" (the owner's call, 2026-11-28, ZANZIBAR-67). Otherwise the capture fails withErrUnpainted("the browser painted none of the page's text"), before the re-measure and the probes. Good captures measured 77–100% inked, the blank ones 0%. The rule and its numbers are the owner's (2026-11-27); - a re-measure with
extract.js, stored asmeta.post: if the height or node count changed, the page moved while it was captured, and the result will carry a warning; - the four probes (
probes.go):probes.jsis installed, then for each oflh,font,controlsandallthe probe is applied, the page re-extracted, and the probe reverted. The four trees are gzipped with a zero mtime, so the same page gives byte-identical files.probes: falsein the job skips them; - a note when the window could not be sized to the viewport, instead of measuring it silently.
-
Failed requests are copied into the capture; those failing with
BLOCKED_BY_CLIENTare counted as blocked (they explain branded browsers). -
Write the JSON last, atomically. Its presence means the capture is complete; on any failure the PNG is removed and
.error.txtholds the error.
Every driver call has a deadline: navigation its own, every other step the script timeout, so a hung renderer cannot stall a job.
The three scripts are the spike's, byte for byte: the precision results were measured with them. SHA256SUMS pins each one; TestEmbeddedScriptsMatchManifest and TestScriptsAreTheSpikeOriginals fail if a script changes (embed.go).
-
The baseline's run a goes first, alone. If it times out, fails to navigate, or renders fewer than 50 elements (a bot wall), the page is unreachable:
failed.jsonis written and nothing else is captured (policy.go).--allow-small-pagesdrops the size rule only.Plan.FullCapture(the lab) disables this policy. -
Then the lanes, in parallel (
lanes):cdp+bidi(Blink and Gecko engines) andclassic(WebKit). Within a lane, captures are sequential: every engine's run a, then every engine's run b (runLane). A page cannot drift between engines, and run b exists to reveal dynamic content. - An engine whose run a failed skips its later runs.
RunPage sees one group of engines at a time: when a job has more engines than --max-browsers, the CLI calls it for every page with each group in turn (CLI and orchestration), and only the first group's Plan names the baseline.
stateDiagram-v2
[*] --> BaselineA: page start
BaselineA --> Unreachable: timeout, navigation error or fewer than 50 elements
Unreachable --> [*]: failed.json
BaselineA --> Lanes: ok
state Lanes {
direction LR
state "cdp+bidi lane" as L1
state "classic lane" as L2
[*] --> L1
[*] --> L2
}
Lanes --> [*]: page done
state "One capture (any lane, any run)" as One {
[*] --> Capture
Capture --> Done: ok, or a non-crash error
Capture --> Relaunch: ErrCrashed
Relaunch --> Retry: fresh browser started
Relaunch --> Lost: browser does not start
Retry --> Done: ok, or a non-crash error
Retry --> Lost: crashed again
Lost --> [*]: reason recorded, later captures skipped
Done --> [*]
}
A capture that fails with ErrCrashed is retried once, in a fresh browser (captureRetrying): Engine.Relaunch replaces the browser (the CLI's restartable wrapper does the work), and the capture runs again. If the retry crashes too, or the browser cannot start again, the engine is lost for the rest of the job: the reason goes into the shared Lost set, the CLI prints one LOST line and sends an engine event with status failed, and every later capture of that engine is written as .error.txt with skipped: <reason>. The other engines go on. A lost baseline does not make a page unreachable: the crash was the browser's, not the page's. Navigation errors and timeouts are never retried.
--resume asks ResumeState per page: a page is done when every engine was attempted to the end (its last run captured or failed, or its run a failed), or when it is marked unreachable. Done pages are skipped. An error file counts as an attempt, unless --retry-failed asks for it again; that flag also retries unreachable pages.
When the job's fontParity is on, the CLI runs the font probe in every engine before its first page (per group, compared with the baseline's report from the first group) (fonts.go): it measures what serif, sans-serif and monospace resolve to (a name counts as resolved only if it measures the same with two different fallbacks behind it, since a missing font falls back silently) and which scripts have an installed font. A mismatch with the baseline, or a script with no font, is a job warning (FontWarnings). omnisnap check-fonts prints the same table. The launch settings in Process management are what make the fonts match; this only verifies them.
| What fails | Result |
|---|---|
| Baseline run a: timeout, navigation error, bot wall | page unreachable, failed.json, nothing else captured |
| Any other capture |
.error.txt; that engine's later runs on the page are skipped |
| A crash | one retry in a fresh browser; then the engine is lost for the job |
| The job's context (Ctrl-C) | the lanes stop; the CLI closes every browser |
- Unit tests with a fake session (
fake_test.go):TestCaptureOnePage,TestScreenshotIsCapped,TestNoNetworkIdleMeansFixedSettle,TestFailureWritesErrorFileOnly(itsunpaintedcase: a blank screenshot of a page with text),TestEveryStepHasADeadline,TestRetryReplacesPreviousAttempt;TestCheckPainted,TestPagePaintedCheckandTestPageRetakesUnpaintedWithElementScreenshots(painted_test.go) for the painted check. - Order and concurrency:
TestRunPageOrder,TestLanesOverlap,TestRunPageReportsFailuresAndContinues(lanes_test.go). - The failure policy and resume:
policy_test.go,resume_test.go. - Crashes:
TestCrashRetriedOnceInAFreshBrowser,TestCrashTwiceLosesTheEngine,TestLostBaselineIsNotUnreachable,TestCrashWithoutRestart,TestNavigationErrorIsNotRetried(crash_test.go). - Probes: written, skippable, byte-deterministic (
probes_test.go). - With real browsers (
browserstag):TestViewportAcrossEngines,TestSingleBlinkCapture,TestProbeCost,TestLaneWallTime(runs only withOMNISNAP_COST=1, on a quiet machine, and prints each lane's wall time) andTestPlantedDiskBudget.
Nothing found for the steps, the failure policy, the crash policy or resume. The WebKit viewport handling has its own delta spec, SPEC-capture-webkit-viewport.md.
-
internal/capture/capture.go:OptionsandResult: viewport and timeouts -
internal/capture/page.go:Page: navigate, settle, capture -
internal/capture/lanes.go:RunPageand the lanes -
internal/capture/crash.go: the crash retry and lost engines -
internal/capture/policy.go: the failure policy and failure.json -
internal/capture/probes.go: the neutralizing probes -
internal/capture/evidence.go: screenshot, post-settle state and probes for a capture -
internal/capture/painted.go: the painted check: a capture whose browser painted none of the page's text fails -
internal/capture/fonts.go: the font check -
internal/capture/resume.go: resuming a page that is already captured -
internal/capture/write.go: writing capture JSON -
assets/inject/embed.go: the injected scripts, embedded and pinned by SHA256SUMS
This wiki is published from docs/internals/ on main. Edits made here are overwritten on the next publish: change the pages there, in a pull request. The specs are normative; where a page and a spec disagree, the page says what the code does.
Start
Contracts
Capture side
Analysis side
Output
Quality