> For the complete documentation index, see [llms.txt](https://chaoslabz.gitbook.io/viewgraph/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://chaoslabz.gitbook.io/viewgraph/tutorials/detect-regressions.md).

# Detect Regressions

Catch structural UI regressions before they reach production.

## Prerequisites

* ViewGraph extension installed and connected
* MCP server running
* A page in a known-good state

## Step 1: Capture the good state

When the page looks correct, capture it and set it as the baseline:

```
Capture this page and set it as the baseline
```

The agent calls `request_capture`, then `set_baseline`. This snapshot becomes the reference point.

## Step 2: Make changes

Edit your code, deploy to staging, or merge a PR. The page may have changed.

## Step 3: Compare against baseline

Capture the page again and compare:

```
Compare the latest capture against the baseline
```

Or use the shortcut: `@vg-diff`

The agent calls `compare_baseline` and reports:

* **Elements removed** - "Submit button (data-testid: submit-btn) is missing"
* **Elements added** - "New div.banner appeared at top of page"
* **Layout shifts** - "Navigation moved 24px down"
* **TestID changes** - "login-btn renamed to sign-in-btn"

## Step 4: Fix or accept

If the changes are intentional, update the baseline:

```
Set the latest capture as the new baseline
```

If they're regressions, fix the code and re-capture to verify.

## Auto-capture for continuous monitoring

Enable auto-capture to detect changes as you develop:

1. Open the Inspect tab in the sidebar
2. Toggle **Auto-capture** on
3. Every time you save a file and HMR reloads, a new capture is created
4. The agent can diff consecutive captures to see what changed

## Multi-step regression detection

For user journeys (login -> dashboard -> settings), capture each step:

```
Record a session: capture login, dashboard, and settings pages
```

The agent calls `analyze_journey` to check for:

* Accessibility regressions between steps
* Missing elements that were present in earlier steps
* Layout inconsistencies across the flow

## What gets compared

| Dimension          | What it catches                                |
| ------------------ | ---------------------------------------------- |
| Element presence   | Buttons, links, inputs that disappeared        |
| TestID stability   | Renamed or removed data-testid attributes      |
| Layout position    | Elements that shifted position                 |
| Element count      | Pages that gained or lost significant elements |
| Structural changes | DOM tree differences                           |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://chaoslabz.gitbook.io/viewgraph/tutorials/detect-regressions.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
