Overview
Agent Browser includes built-in diff commands for comparing page states, making it ideal for:- Visual regression testing
- Detecting unintended changes between deployments
- Comparing staging vs production
- Monitoring page changes over time
- Testing responsive design at different breakpoints
- Snapshot diff - Text-based comparison using the Myers diff algorithm
- Screenshot diff - Pixel-based visual comparison using Canvas API
- URL diff - Compare two different URLs side-by-side
Snapshot Diff
Compare accessibility tree snapshots to detect structural changes.Compare Current vs Last Snapshot
Scoped Snapshot Diff
Compare only a specific section of the page:Compact Diff
Remove empty structural elements for cleaner comparison:Implementation Details
The snapshot diff uses the Myers diff algorithm for efficient line-level comparison. Seesrc/diff.ts for the implementation:
equal- Lines that are unchangedinsert- Lines added in the new snapshotdelete- Lines removed from the old snapshot
Screenshot Diff
Compare images pixel-by-pixel to detect visual changes.Basic Screenshot Diff
Custom Output Path
Adjust Color Threshold
Control sensitivity to color differences (0-1, default 0.1):Implementation Details
Screenshot diff uses the browser’s Canvas API for pixel comparison. Seesrc/diff.ts:160-340:
- Isolated page: Diff runs in a separate page to avoid CSP issues
- Route interception: Images served via routes instead of base64 in
page.evaluate()to avoid CDP message size limits - Euclidean distance: Color differences calculated in RGB space
- Output image: Different pixels highlighted in red, matching pixels dimmed to 30% brightness
Dimension Mismatch
If images have different dimensions, the diff will fail:URL Diff
Compare two different URLs directly.Snapshot Diff Between URLs
Screenshot Diff Between URLs
Custom Wait Strategy
Wait for specific load state before comparing:Scoped URL Diff
Compare only a specific section:Testing Workflows
Visual Regression Testing
Detect unintended visual changes between deployments:Responsive Design Testing
Compare page layout at different breakpoints:Monitoring Changes Over Time
Detect changes to a page over time:CI/CD Integration
Integrate diff testing into continuous integration:Best Practices
Snapshot Diff
- Use compact mode for cleaner diffs:
--compact - Scope to relevant sections to reduce noise:
--selector "#main" - Wait for dynamic content before diffing:
agent-browser wait --load networkidle - Store baselines in version control for reproducibility
Screenshot Diff
-
Set consistent viewport before screenshots:
-
Adjust threshold based on your needs:
- Strict:
-t 0.05(detects subtle changes) - Moderate:
-t 0.1(default, good balance) - Lenient:
-t 0.3(ignores minor variations)
- Strict:
-
Wait for animations to complete:
-
Use full page screenshots for complete comparison:
-
Hide dynamic elements (timestamps, ads) before comparison:
URL Diff
- Use —wait-until networkidle for dynamic pages
- Scope to stable sections to avoid flaky diffs
- Set viewport size for consistent layout
- Authenticate before diffing if comparing logged-in pages:
Limitations
Snapshot Diff
- Text-based only - Does not detect visual styling changes (colors, fonts, spacing)
- Structure-dependent - Minor HTML restructuring can cause large diffs
- Ref numbers change - Refs (
@e1,@e2) are not stable across snapshots
Screenshot Diff
- Dimension mismatch - Images must have identical dimensions
- Dynamic content - Timestamps, ads, and animations cause false positives
- Antialiasing differences - Font rendering can vary across environments
- Performance - Pixel comparison can be slow for large images
See Also
- Snapshot Reference - Understanding accessibility tree snapshots
- Screenshot Commands - Screenshot options and formats
- Troubleshooting - Common diff testing issues