# Visual Regression & Screenshot Diff for AI Agents (`fluidfaith/visual-diff-gate`) Actor

Compare two web pages (production vs preview, before vs after a deploy) on desktop and phone sizes: percent of pixels changed, changed regions as boxes, a diff image and PASS or FAIL. Visual regression testing for AI agents and MCP. $0.005 per page pair per viewport.

- **URL**: https://apify.com/fluidfaith/visual-diff-gate.md
- **Developed by:** [FFS Marketing](https://apify.com/fluidfaith) (community)
- **Categories:** Developer tools, AI, Automation
- **Features:** Limited permissions
- **Stats:** 2 total users, 1 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$5.00 / 1,000 page pair compared on one viewports

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Visual Regression & Screenshot Diff for AI Agents

**Compare two web pages, for example production and a preview deploy, on desktop and phone sizes, and get back the percent of pixels that changed, every changed region as a box, a diff image and a PASS or FAIL verdict.** It answers the question a coding agent should ask after every change: "did my edit move or break something I did not mean to touch?" The check runs outside the agent's own code, so the agent cannot quietly patch the test to make it pass.

**Works as a tool for AI agents.** Add it to Claude, ChatGPT, Cursor, VS Code or any MCP client through Apify's MCP server (`https://mcp.apify.com/?tools=fluidfaith/visual-diff-gate`), or call it with one API request. JSON in, JSON out, one overall verdict in `OUTPUT`. Setup is in [Use it from an agent](#use-it-from-an-agent).

**Costs $0.005 per page pair per viewport.** One page on desktop and phone is $0.01. Pages that fail to load are free, and your maximum charge per run is never exceeded.

#### Why use it

- **A verdict, not just a picture.** PASS or FAIL against the change you allow (default 0.2% of pixels), plus `diffPercent`, `changedPixels` and `heightChanged`.
- **Changed regions an agent can reason about.** Each change comes back as a box (`x`, `y`, `width`, `height`, changed pixels), largest first, so the agent can tell "one word changed in the hero" from "the whole pricing section moved down 120px".
- **Production vs preview in one call.** Give two site addresses and a list of paths (`/`, `/pricing`, `/blog`), and every path is compared on every viewport.
- **Steady results.** Fonts are pinned, animations are finished or stopped, lazy images are scrolled into view, the caret is hidden. Mask the parts that change on every load (clocks, carousels, ads) and hide cookie banners.
- **Desktop, laptop, tablet and today's phones:** the same phone sizes as [Mobile QA Gate](https://apify.com/fluidfaith/mobile-qa-gate) (iPhone 15 to 18, Galaxy, Pixel), or any size like `1024x768`.

### What you get

| Field | What it is |
|---|---|
| `verdict` | `PASS`, `FAIL` or `ERROR` (could not be compared, not charged). |
| `diffPercent` | Percent of pixels that changed, for example `0.2864`. |
| `changedPixels`, `totalPixels` | The raw counts behind `diffPercent`. |
| `regions` | Up to 20 changed regions, largest first: `{ x, y, width, height, changedPixels }` in CSS pixels from the top left of the page. |
| `regionCount` | How many separate changed regions there were in total. |
| `heightChanged`, `baselineHeight`, `candidateHeight` | Whether the page got taller or shorter. The extra area counts as changed. |
| `diffImageUrl` | PNG: the baseline page faded to grey, changed pixels in red (anti-aliasing edges in yellow). |
| `baselineImageUrl`, `candidateImageUrl` | The two screenshots (PNG). |
| `baselineStatus`, `candidateStatus` | HTTP status of each page. |
| `warnings`, `error` | Anything worth knowing (page cut at the height limit, blocked embeds) and why a comparison failed. |

### Input

Two ways to give pages; you can use both in one run.

**Pairs of URLs:**

```json
{
  "pairs": [
    { "name": "home", "baseline": "https://www.example.com/", "candidate": "https://preview-123.example.pages.dev/" },
    { "name": "pricing", "baseline": "https://www.example.com/pricing", "candidate": "https://preview-123.example.pages.dev/pricing" }
  ],
  "viewports": ["Desktop", "iPhone 15-16"]
}
```

**Two sites plus paths** (production vs preview):

```json
{
  "baselineOrigin": "https://www.example.com",
  "candidateOrigin": "https://preview-123.example.pages.dev",
  "paths": ["/", "/pricing", "/blog"],
  "viewports": ["Desktop", "iPhone 15-16"],
  "maskSelectors": [".testimonial-carousel", "#live-visitors"],
  "hideSelectors": ["#cookie-banner"]
}
```

| Field | Default | Notes |
|---|---|---|
| `pairs` | none | `{ baseline, candidate, name }` objects, up to 100 pairs. |
| `baselineOrigin`, `candidateOrigin`, `paths` | `paths`: `["/"]` | Each path becomes one pair. |
| `viewports` | `["Desktop", "iPhone 15-16"]` | Presets: `Desktop` (1440x900), `Laptop` (1280x800), `Tablet` (820x1180), `iPhone 15-16`, `iPhone 17-18 Pro`, `iPhone 18 Pro Max`, `Galaxy S`, `Pixel`, or any `WIDTHxHEIGHT` from 320 to 2560. Up to 10. Each viewport is billed separately. |
| `maxDiffPercent` | `0.2` | FAIL above this percent of changed pixels. `0` fails on any changed pixel. |
| `pixelThreshold` | `0.1` | Colour sensitivity, 0 (any difference) to 1. 0.1 ignores tiny colour noise. |
| `fullPage` | `true` | Compare the whole scrolling page. `false` compares the first screen only. |
| `maxPageHeight` | `8000` | Pages taller than this (CSS px) are compared from the top down to this height. Up to 20000. |
| `maskSelectors` | `[]` | CSS selectors painted over in both screenshots (they never count as changed). |
| `hideSelectors` | `[]` | CSS selectors made invisible before the screenshot. |
| `waitAfterLoadMs` | `800` | Extra wait after the load event. |
| `navigationTimeoutSecs` | `45` | Page load limit. |
| `saveImages` | `true` | Save the diff image and both screenshots and return their links. |
| `maxConcurrency` | `2` | Pairs compared at the same time (up to 3). |
| `proxyConfiguration` | none | Optional Apify proxy for sites that block data-center traffic. |

### Output

One dataset row per pair per viewport (example, trimmed):

```json
{
  "name": "pricing",
  "baselineUrl": "https://www.example.com/pricing",
  "candidateUrl": "https://preview-123.example.pages.dev/pricing",
  "viewport": "iPhone 15-16",
  "viewportSize": { "width": 393, "height": 852 },
  "verdict": "FAIL",
  "diffPercent": 1.0493,
  "changedPixels": 7555,
  "totalPixels": 719976,
  "maxDiffPercent": 0.2,
  "baselineHeight": 1832,
  "candidateHeight": 1832,
  "heightChanged": false,
  "regionCount": 2,
  "regions": [
    { "x": 41, "y": 515, "width": 101, "height": 42, "changedPixels": 3778 },
    { "x": 41, "y": 321, "width": 101, "height": 42, "changedPixels": 3777 }
  ],
  "diffImageUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/<key>-iPhone1516-diff",
  "baselineImageUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/<key>-iPhone1516-baseline",
  "candidateImageUrl": "https://api.apify.com/v2/key-value-stores/<storeId>/records/<key>-iPhone1516-candidate",
  "baselineStatus": 200,
  "candidateStatus": 200,
  "warnings": [],
  "error": null
}
```

The run's `OUTPUT` record holds one overall answer, the easiest thing for an agent to branch on:

```json
{ "verdict": "FAIL", "comparisons": 4, "passed": 3, "failed": 1, "errors": 0,
  "results": [ { "name": "pricing", "viewport": "iPhone 15-16", "verdict": "FAIL", "diffPercent": 1.0493, "regionCount": 2, "diffImageUrl": "..." } ] }
```

If the run stops at your maximum charge, `OUTPUT` also has `"stoppedAtSpendingCap": true` and `"notCompared": <count>`.

### Use it from an agent

#### Through Apify's MCP server (Claude, ChatGPT, Cursor, VS Code, any MCP client)

```json
{
  "mcpServers": {
    "visual-diff-gate": {
      "url": "https://mcp.apify.com/?tools=fluidfaith/visual-diff-gate",
      "headers": { "Authorization": "Bearer <APIFY_TOKEN>" }
    }
  }
}
```

**Claude Code:** `claude mcp add --transport http visual-diff-gate "https://mcp.apify.com/?tools=fluidfaith/visual-diff-gate" --header "Authorization: Bearer $APIFY_TOKEN"`. **Claude Desktop:** paste the JSON above into Settings > Developer > Edit config. Or run it over stdio: `npx -y @apify/actors-mcp-server --tools fluidfaith/visual-diff-gate` with `APIFY_TOKEN` set.

A good instruction for coding agents: *"Before you report a front-end change as done, call visual-diff-gate with production as the baseline and your preview deploy as the candidate. Every changed region must be one you meant to change. Open diffImageUrl for any FAIL."*

#### Through the API (one call, waits for the result)

```bash
curl -s -X POST "https://api.apify.com/v2/acts/fluidfaith~visual-diff-gate/run-sync-get-dataset-items?token=$APIFY_TOKEN" \
  -H 'Content-Type: application/json' \
  -d '{"baselineOrigin":"https://www.example.com","candidateOrigin":"https://preview.example.com","paths":["/"]}'
```

#### From JavaScript

```js
import { ApifyClient } from 'apify-client';
const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('fluidfaith/visual-diff-gate').call({
  baselineOrigin: 'https://www.example.com', candidateOrigin: 'https://preview.example.com', paths: ['/', '/pricing'],
});
const { value } = await client.keyValueStore(run.defaultKeyValueStoreId).getRecord('OUTPUT');
if (value.verdict !== 'PASS') console.log(value.results.filter((r) => r.verdict !== 'PASS'));
```

### Pricing

Pay per event: **$0.005 per page pair per viewport** (`viewport-pair-compared`).

| Example | Cost |
|---|---|
| 1 page, desktop and phone | $0.01 |
| 10 pages, desktop and phone | $0.10 |
| 50 pages on 4 viewports | $1.00 |

Pages that never arrive, return an error status, are refused or hit the time limit are free. A page whose load event is slow but whose content arrived is still compared (with a warning). If you set a maximum charge per run, the Actor sets aside the cost of each comparison before starting it, so it never charges past your maximum, even with pairs running in parallel. It stops starting new comparisons when the budget is used up and still writes `OUTPUT`.

### Safety

- Only public web addresses are compared. Localhost, private networks (10.x, 172.16-31.x, 192.168.x), link-local and cloud metadata addresses (169.254.x), CGNAT, IPv6 loopback and private ranges, and `.local` / `.internal` names are refused, also when a public page redirects to them. Embedded frames that point at them are blocked and noted in `warnings`. Refused pages are `ERROR` and not charged.
- Hard time limits on every page load and on the whole comparison: a page that never answers or a script that never stops becomes an `ERROR` row (not charged) instead of holding the run.
- Pages are loaded as an anonymous visitor: no login, no clicks, no forms.
- Image links point to the run's key-value store and can be opened by anyone with the link. Keep that in mind for private preview builds.

### Privacy

Pages are loaded in the run, and the screenshots and results are kept only in your own run storage for your account's retention period. Query strings are left out of the run log.

### FAQ

**Can it compare a preview or staging deploy?** Yes, if the URL is publicly reachable (Vercel, Netlify and Cloudflare Pages preview links work). Localhost and private networks are refused.

**Why did an unchanged page FAIL?** Something on it changes on every load: a clock, a rotating testimonial, an ad, a random image. Add its CSS selector to `maskSelectors`. The `regions` boxes show where to look.

**Why did a changed word PASS?** One word is usually under the default 0.2%. It is still listed in `regions`. Set `maxDiffPercent` to `0` to fail on any change.

**The page got taller. Why is half of it red?** When content is added, everything below it moves down, so it all counts as changed, and the extra height counts too. `heightChanged` and the first region's `y` tell you where the shift starts.

**Can I compare against a saved screenshot?** Not yet: both sides are live pages. Keep production as the baseline, or compare two deploy URLs.

**What happens at my spending limit?** The Actor stops before the comparison that would go over it, writes `OUTPUT` with `stoppedAtSpendingCap: true`, and charges nothing past the limit.

**How do I get help?** Open an issue on the Issues tab. We read and answer every one.

### Other Actors by Fluid Faith

- [Mobile Website Test on iPhone & Android (Mobile QA Gate)](https://apify.com/fluidfaith/mobile-qa-gate): PASS or FAIL per page on today's phones, with screenshots. $0.01 per page per phone.
- [Lighthouse & Accessibility Audit](https://apify.com/fluidfaith/lighthouse-gate): Lighthouse scores, Core Web Vitals and axe-core issues with the top 5 fixes. $0.02 per URL per form factor.
- [PDF to Markdown with Tables](https://apify.com/fluidfaith/pdf-to-markdown-tables): PDF, Word, PowerPoint and Excel to Markdown with every table as JSON rows. $0.002 per page.
- [Video Frame Extractor & Media Probe](https://apify.com/fluidfaith/media-probe): ffprobe metadata, frames, scene cuts, a contact sheet and loudness from direct video or audio links. $0.001 per frame.

Load them together as MCP tools: `https://mcp.apify.com/?tools=fluidfaith/visual-diff-gate,fluidfaith/mobile-qa-gate,fluidfaith/lighthouse-gate,fluidfaith/pdf-to-markdown-tables,fluidfaith/media-probe`

# Actor input Schema

## `pairs` (type: `array`):

List of {"baseline": url, "candidate": url, "name": optional label}. Up to 100 pairs. Only public web addresses: localhost, private networks and internal hosts are refused.

## `baselineOrigin` (type: `string`):

Shortcut for many pages: the reference site, for example https://www.yoursite.com. Used with "Candidate site" and "Paths"; each path becomes one pair.

## `candidateOrigin` (type: `string`):

The new version of the same site, for example a preview deploy https://my-branch.yoursite.pages.dev.

## `paths` (type: `array`):

Paths compared on both sites, each starting with "/". Default: just the home page.

## `viewports` (type: `array`):

Screen sizes to compare on. Presets: Desktop (1440x900), Laptop (1280x800), Tablet (820x1180), iPhone 15-16 (393), iPhone 17-18 Pro (402), iPhone 18 Pro Max (440), Galaxy S (360), Pixel (412). Or any size written like 1024x768. Each viewport is billed separately.

## `maxDiffPercent` (type: `number`):

FAIL when more than this percent of pixels changed. 0.2 by default: a few changed words pass, a moved section fails. Use 0 to fail on any changed pixel.

## `pixelThreshold` (type: `number`):

How different two pixels must be to count as changed, from 0 (any difference) to 1. 0.1 by default, which ignores tiny colour noise.

## `fullPage` (type: `boolean`):

Compare the whole scrolling page (up to the maximum height). Turn off to compare only the first screen.

## `maxPageHeight` (type: `integer`):

Pages taller than this are compared from the top down to this height.

## `maskSelectors` (type: `array`):

CSS selectors of parts that change on every load (dates, carousels, ads, live counters). They are painted over in both screenshots so they never count as changed.

## `hideSelectors` (type: `array`):

CSS selectors made invisible before the screenshot, for example cookie banners or chat widgets.

## `waitAfterLoadMs` (type: `integer`):

Time for late scripts and fonts after the load event, before the screenshot.

## `navigationTimeoutSecs` (type: `integer`):

How long to wait for each page. A page that never arrives makes that comparison ERROR, which is not charged.

## `saveImages` (type: `boolean`):

Save the diff image and both screenshots (PNG) to the key-value store and return their links.

## `maxConcurrency` (type: `integer`):

How many pairs are compared at the same time (each opens two pages).

## `proxyConfiguration` (type: `object`):

Optional Apify proxy for sites that block data-center traffic.

## Actor input object example

```json
{
  "pairs": [
    {
      "name": "home",
      "baseline": "https://example.com",
      "candidate": "https://example.org"
    }
  ],
  "paths": [
    "/"
  ],
  "viewports": [
    "Desktop",
    "iPhone 15-16"
  ],
  "maxDiffPercent": 0.2,
  "pixelThreshold": 0.1,
  "fullPage": true,
  "maxPageHeight": 8000,
  "maskSelectors": [],
  "hideSelectors": [],
  "waitAfterLoadMs": 800,
  "navigationTimeoutSecs": 45,
  "saveImages": true,
  "maxConcurrency": 2
}
```

# Actor output Schema

## `results` (type: `string`):

No description

## `summary` (type: `string`):

No description

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "pairs": [
        {
            "name": "home",
            "baseline": "https://example.com",
            "candidate": "https://example.org"
        }
    ]
};

// Run the Actor and wait for it to finish
const run = await client.actor("fluidfaith/visual-diff-gate").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = { "pairs": [{
            "name": "home",
            "baseline": "https://example.com",
            "candidate": "https://example.org",
        }] }

# Run the Actor and wait for it to finish
run = client.actor("fluidfaith/visual-diff-gate").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "pairs": [
    {
      "name": "home",
      "baseline": "https://example.com",
      "candidate": "https://example.org"
    }
  ]
}' |
apify call fluidfaith/visual-diff-gate --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,fluidfaith/visual-diff-gate"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/Z5yazqTVQ3ZAN5ddQ/builds/JsGaPet7R9FrPo6Eo/openapi.json
