Visual regression

From shogo-labs/shogo-ai · View interactive version

Visual regression is an AI agent skill from the GitHub repository shogo-labs/shogo-ai. Screenshot comparison and visual regression detection across viewports

How to use this skill

Skill file

Visual Regression Testing

Detect unintended visual changes by comparing screenshots against stored baselines.

Workflow

1. Capture Baselines

First run establishes the "known good" state:

  1. Navigate to each critical page at all 3 viewports
  2. Wait for networkidle to ensure all assets loaded
  3. Take full-page screenshots
  4. Store baseline metadata in memory:

```json

{

"page": "/dashboard",

"viewport": "desktop",

"path": "/tmp/baseline-dashboard-desktop-1700000000.png",

"commitHash": "abc123",

"timestamp": "2024-01-15T10:30:00Z",

"url": "http://localhost:3000/dashboard"

}

```

2. Comparison Run

On subsequent runs:

  1. Take new screenshots at the same pages and viewports
  2. Compare against stored baselines pixel-by-pixel
  3. Calculate the percentage of changed pixels
  4. Flag pages that exceed the threshold

3. Diff Analysis

Threshold configuration:

The user can adjust per-page if needed.

4. Report Results

Present findings with:

Viewport Matrix

| Viewport | Width | Height | Use Case |

|----------|-------|--------|----------|

| Desktop | 1920 | 1080 | Primary layout, full navigation |

| Tablet | 768 | 1024 | Responsive breakpoint, touch layout |

| Mobile | 375 | 667 | Mobile-first, hamburger menu, stacked layout |

Baseline Management

Comparison Script Template

const { chromium } = require('playwright');
const fs = require('fs');

const TARGET_URL = 'http://localhost:3000';
const PAGES = ['/', '/dashboard', '/settings', '/profile'];
const VIEWPORTS = [
  { name: 'desktop', width: 1920, height: 1080 },
  { name: 'tablet', width: 768, height: 1024 },
  { name: 'mobile', width: 375, height: 667 },
];

(async () => {
  const browser = await chromium.launch({ headless: false });
  const results = [];

  for (const pagePath of PAGES) {
    for (const vp of VIEWPORTS) {
      const context = await browser.newContext({
        viewport: { width: vp.width, height: vp.height }
      });
      const page = await context.newPage();
      await page.goto(`${TARGET_URL}${pagePath}`);
      await page.waitForLoadState('networkidle');

      const screenshotPath = `/tmp/vr-${pagePath.replace(/\//g, '-')}-${vp.name}-${Date.now()}.png`;
      await page.screenshot({ path: screenshotPath, fullPage: true });

      results.push({
        page: pagePath,
        viewport: vp.name,
        screenshot: screenshotPath,
        timestamp: new Date().toISOString()
      });

      console.log(`✓ Captured ${pagePath} @ ${vp.name}`);
      await context.close();
    }
  }

  console.log(JSON.stringify(results, null, 2));
  await browser.close();
})();

Edge Cases to Handle

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.