feat: add responsive snapshot capture, cookie capture, and cross-origin iframe support#25
Conversation
…e support - Add responsive snapshot capture with CLI widths-config integration - Add cross-origin iframe processing via processFrame() and getSerializedDOM() - Add cookie capture using page.context().cookies() - Parse cliConfig from healthcheck for responsive capture detection - Add HTTP status checks with clear error messages for failed requests - Update logging to always show responsive capture errors - Add 600s timeout for snapshot requests, 30s for widths-config - Support PERCY_RESPONSIVE_CAPTURE_RELOAD_PAGE and RESPONSIVE_CAPTURE_SLEEP_TIME env vars
There was a problem hiding this comment.
Pull request overview
Adds new snapshot-capture capabilities to the Percy Playwright Java SDK (responsive multi-viewport capture, cookie attachment, and cross-origin iframe stitching) along with CLI-driven configuration and improved logging/timeout behavior.
Changes:
- Implement responsive snapshot capture driven by CLI
/percy/widths-config, with viewport resizing/reload/sleep support. - Attach cookies and captured cross-origin iframe snapshots into the DOM snapshot payload.
- Add structured CLI logging, request timeouts, and tests/fixtures for the new behaviors.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
src/main/java/io/percy/playwright/Percy.java |
Core implementation for responsive capture, cookie capture, CORS iframe capture, CLI config caching, structured logging, and HTTP timeouts |
src/test/java/io/percy/playwright/SDKTest.java |
Adds unit/integration tests for responsive capture, cookies, and CORS iframes |
src/test/resources/testapp/cors-iframe.html |
New fixture page embedding a cross-origin iframe |
package.json |
Updates Percy CLI devDependency to an alpha version range |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Refactoring Log Request Body construction Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
error handling for cors iframe url check Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 5 out of 5 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
This PR introduces three new snapshot capture features to the Percy Playwright Java SDK:
snapshot()call.data-percy-element-id.Feature Details
1. Responsive Snapshot Capture
snapshot()now checksisCaptureResponsiveDOM()to decide between a single capture and a multi-width responsive capture.options.put("responsiveSnapshotCapture", true)snapshot.responsiveSnapshotCapture: truepercy.deferUploads: true(not compatible with deferred uploads)GET /percy/widths-config.window.resizeCount(viaPercyDOM.waitForResize()) → optionally reloads → optionally sleeps → captures DOM.New environment variables:
RESPONSIVE_CAPTURE_SLEEP_TIMEPERCY_RESPONSIVE_CAPTURE_RELOAD_PAGEtrue/false)PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHTouterHeight - innerHeight + minH2. Cookie Capture
page.context().cookies()is collected (with graceful fallback on failure).name,value,domain,path,expires,httpOnly,secure,sameSite) and attached ascookiesin the snapshot payload.3. Cross-Origin (CORS) Iframe Capture
getSerializedDOM()filterspage.frames()to find frames whose host differs from the main page host.PercyDOM.serialize({enableJavaScript: true})→ retrieves the matchingdata-percy-element-idfrom the main page DOM.corsIframesin the snapshot payload.cors-iframe.htmlembedshttps://todomvc.com/examples/react/dist/to provide a real cross-origin frame for integration testing.Other Changes
request()now uses a 600-second socket/connect timeout (was none), preventing long snapshot posts from hanging indefinitely.configobject, used to drive responsive capture and deferUploads behavior without restarting.log()now POSTs{message, level}JSON to the Percy CLI/percy/logendpoint in addition to printing to stdout. Debug-level messages are suppressed from stdout unlessPERCY_LOGLEVEL=debug.@percy/clito^1.31.10-alpha.0to pick up thewidths-configand/percy/logendpoints.Tests
isCaptureResponsiveDOM— SDK option, CLI config, anddeferUploadsoverride.