# Screenshots and visual inspection

> Validate results with structured readback, rendered screenshots, and slide layout checks.

- Human documentation: [https://docs.univer.ai/overview/features/shared/visual-inspection](https://docs.univer.ai/overview/features/shared/visual-inspection)

- Agent Markdown: [https://docs.univer.ai/overview/features/shared/visual-inspection.md](https://docs.univer.ai/overview/features/shared/visual-inspection.md)

- Requested language: `en-US`

- Content language: `en-US`

- Documentation version: `1.6.1`

- Source: [features/shared/visual-inspection.mdx](https://github.com/dream-num/documentation/blob/dev/content/docs/features/shared/visual-inspection.mdx)

---

Visual inspection converts a content model into images and layout evidence that can be examined. An agent verifies the data and the formulas first, then examines the rendered text, shapes, and pages. When it finds a problem, it corrects the content through a Facade and examines the resulting state again.

## Three kinds of evidence

| Evidence | What it can establish |
| --- | --- |
| Structured readback | Raw values, formulas and their results, and paragraph and object properties. |
| PNG screenshot | The content that is actually visible, including clipping, charts, colors, and overall composition. |
| Layout diagnostics | Rules, object IDs, bounds, and issue locations derived from the render, which identify the object to correct. |

## Prepare content state and dependencies

Screenshot and Layout Lint operate on materialized UnitData. They do not connect to a remote target, and they do not interpret changesets. For collaborative content, call `pull()`, wait for calculation to finish after a formula edit, and then call `exportUnitData()`. In a Worktree, export the draft that is intended for inspection. An application can record the target, the revision, and the scope alongside the report, so that a review refers to one known state.

A host Snapshot does not include every dependency. Pass Sheet and Relational Table sources through `formulaReferenceUnits`, and pass child content through `embeddedUnits`. The Render Page materializes the dependencies before the host, so formulas and blocks load with their sources already in place. UUID image assets can be prepared with `resolveUnitScreenshotImageAssets()` and a resolver from the application. Resolution is best-effort, so missing resources require verification as well.

## From content to a stable image

```mermaid
flowchart LR
A["Explicit content state<br/>UnitData + dependencies"]
B["Render Runtime<br/>Browser and page protocol"]
C["Render Page<br/>Native Univer layout"]
D["Readiness checks<br/>Calculation and stable image"]
E["PNG / layout facts<br/>Agent and human review"]
A --> B --> C --> D --> E
```

`univer-render-runtime` hosts a Render Page built by the application and starts a browser from Node.js. Product plugins restore the content on that page, and both sides check the page protocol version. A Runtime executes its operations through a single serial queue, so the same Runtime can be retained across inspection rounds. The owner of the Runtime calls `close()` when the work is complete.

Readiness depends on the product. Formula-driven Shapes wait until results leave pending and, where necessary, until the pixels remain unchanged across frames, so that a transitional animation is not captured. Relational Table waits for fonts, calculation, the active table or view, and a stable DOM and Canvas layout. A formula result that has left pending can still be an error, so both its value and its status require verification.

The current implementation hashes the serialized host UnitData, the formula sources, and the embedded children into a render session key. Changed content receives a new key even when the Unit ID remains the same, so an old image is never reused solely because the ID matches.

## Choose the scope by product

| Product | Scope and output |
| --- | --- |
| Sheet | Select a worksheet and an A1 range to obtain a region PNG. Select important results explicitly. |
| Doc | Select pages, or enumerate them, to obtain one PNG per page. |
| Slide | Select 1-based page numbers or page IDs, and optionally add a contact sheet. |
| Relational Table | Capture the workbench as it opens, including its active table or view, from the browser DOM and Canvas. |
| Canvases | Use the content bounds, or a region / elementIds selector; the two are mutually exclusive. Padding and layout evidence are optional. |

`unit-screenshot` returns the image bytes, the dimensions, the page or range identity, and suggested file names; the application saves them. The scale factor accepts 0.1–4. Set `maxPages` and the per-image `maxPixels`. Doubling the scale produces roughly four times the pixels, so inspect large content in regions. PDF is outside this screenshot entry point, which covers the five products above.

## Share rendering for screenshots and lint

The example captures and lints the same Slide data and formula sources. `renderRuntime` is an existing render Runtime, and `slideData` is the prepared snapshot. Neither capability writes files. For page construction and resource cleanup, see [AI SDK visual inspection](https://docs.univer.ai/ai/visual-inspection.md).

```ts
import { createUnitScreenshot } from '@univer-cli/unit-screenshot'
import { createUnitLayoutLint } from '@univer-cli/unit-layout-lint'

const source = {
  unitType: 'slide' as const,
  unitData: slideData,
  formulaReferenceUnits,
}
const screenshot = createUnitScreenshot({ runtime: renderRuntime })
const lint = createUnitLayoutLint({ runtime: renderRuntime })

const capture = await screenshot.capture({
  ...source,
  target: { kind: 'slide-pages', pages: [1], scale: 2 },
})
const report = await lint.lint({ ...source, pages: [1] })
```

## Slide: locate problems using glyph ink

Layout Lint works from the layout facts that the browser produces. An element's `declared` box describes its geometry in the model, while text `ink` describes the area that the glyphs actually cover, mapped into page coordinates with layout, alignment, and rotation. A text box that fits on the page does not prove that its glyphs fit.

| Current rule | Evidence checked |
| --- | --- |
| `text-off-page` | The actual text ink extends past the page edge. |
| `text-escapes-container` | Text visibly overflows a matched opaque container that is smaller. |
| `text-overlaps-text` | Two actual text ink areas overlap substantially. |

A report includes `coverage.pages` and `coverage.rules`. Each finding carries `pageId`, the element `id`, the `text.ink`, and the relevant `overflow`, `container`, or `other` evidence. A stable `fingerprint` simplifies comparison between repair rounds. Findings are currently warnings and are intended to be read alongside the screenshots. An empty list only means that the selected scope triggered none of these rules.

## Canvases: inspect rendered connector routes

Canvases screenshots also return `layoutAnalysis`, which contains the routes resolved by the browser, the issues, and a summary. This is separate from `unit-layout-lint`, which only handles Slide. Automatic connector paths may be unresolved in the model, so inspect the final routes through the evidence with `source: 'rendered'`.

Diagnostics can identify connectors that cross elements or intersect, colliding arrowheads, and conflicting labels, and report the corresponding `connectorIds`, `elementIds`, and `focusBounds`. Correct the objects involved, capture a region or an element set, and then review the whole canvas again. This associates a visual concern with one specific Facade edit.

## Include evidence in the handoff

```mermaid
flowchart LR
A["Facade edit"]
B["Read back data and formulas"]
C["Screenshot + diagnostics"]
D["Repair by object ID"]
E["Check the new state"]
F["Human review / handoff"]
A --> B --> C --> D --> E --> F
D --> B
```

Keep the structured results, the scope and page information, the images, and the diagnostics together. A screenshot does not establish that formulas are correct, and lint does not replace visual judgment. Interactions that involve the toolbar, focus, and popups still require verification in the Web editor, and cross-Unit dependencies must be loaded.

Run these checks before a [Worktree](https://docs.univer.ai/overview/features/shared/worktree.md) is marked Ready, so that the reviewer can match content changes to evidence. See [headless and server calculation](https://docs.univer.ai/overview/features/shared/server-calculation.md) for execution and [Agents and automation](https://docs.univer.ai/overview/features/shared/agents.md) for orchestration.

[Back to features](https://docs.univer.ai/overview/features.md)
