Feat : responsive capture feature and Cross Origin Iframe capture#302
Feat : responsive capture feature and Cross Origin Iframe capture#302yashmahamulkar-bs merged 15 commits intomasterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR enhances the Java Selenium SDK’s snapshotting to better support responsive DOM capture (by retrieving width/height config from the Percy CLI) and to include cross-origin iframe DOM snapshots during serialization.
Changes:
- Added
/percy/widths-configclient (getResponsiveWidths) and refactored responsive capture to use it, with optional reload/min-height behavior via env vars. - Added cross-origin iframe detection + per-iframe serialization (
processFrame) and attaches results undercorsIframesin the DOM payload. - Updated
@percy/clidev dependency to a newer alpha version to support the new CLI endpoint/features.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.
| File | Description |
|---|---|
| src/main/java/io/percy/selenium/Percy.java | Adds widths-config fetching, responsive capture updates, and cross-origin iframe snapshot serialization. |
| package.json | Bumps @percy/cli version to support new responsive capture behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
This PR enhances the Percy Selenium Java SDK’s snapshotting flow by improving responsive DOM capture (width/height config fetched from the Percy CLI) and adding cross-origin iframe serialization so CORS iframes can be included in DOM snapshots.
Changes:
- Added
/percy/widths-configfetch + new env-var driven behavior for responsive capture (reload between widths, optional min-height handling). - Added cross-origin iframe processing and inclusion in the serialized snapshot payload (
corsIframes). - Expanded
SdkTestcoverage for responsive capture gating, widths-config parsing/errors, and CORS iframe serialization; updated@percy/clidev dependency.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/main/java/io/percy/selenium/Percy.java | Implements responsive-width fetching, optional reload/min-height handling, and CORS iframe capture during DOM serialization. |
| src/test/java/io/percy/selenium/SdkTest.java | Adds tests validating responsive capture logic, widths-config behavior, and cross-origin iframe serialization. |
| package.json | Updates Percy CLI dev dependency to an alpha version needed for new features. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
|
||
| public List<Map<String, Object>> captureResponsiveDom(WebDriver driver, Set<Cookie> cookies, Map<String, Object> options) { | ||
| List<Integer> responsiveWidths = extractResponsiveWidths(options); | ||
| List<Map<String, Object>> widths = getResponsiveWidths(responsiveWidths); |
There was a problem hiding this comment.
[CRITICAL] snapshot() only catches WebDriverException — RuntimeException from new code paths crashes callers
getResponsiveWidths() (called here) throws RuntimeException on HTTP failures (non-200 status, missing widths key). Similarly, getSerializedDOM() can propagate RuntimeException from fatal iframe errors. However, the snapshot(String, Map) method that calls captureResponsiveDom() only catches WebDriverException at line 367.
Since RuntimeException is not a subclass of WebDriverException, these exceptions propagate uncaught to the caller, crashing their test suite. Percy snapshots should never crash the calling test — they should fail gracefully and return null.
Suggested fix:
try {
// ... existing code ...
} catch (WebDriverException e) {
log(e.getMessage(), "debug");
} catch (Exception e) {
log("Snapshot failed: " + e.getMessage(), "debug");
}…ponsive capture - Catch Exception (not just WebDriverException) in snapshot() to prevent caller crashes - Wrap captureResponsiveDom loop in try/finally to always restore window size - Replace System.out.println debug statements with log() calls - Introduce FatalIframeException to replace fragile string matching on "Fatal" - Fix log(String) indentation - Add fallback for renamed RESONSIVE_CAPTURE_SLEEP_TIME env var Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…manager Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This pull request introduces several improvements and refactors to the
Percy.javacodebase, primarily enhancing responsive DOM capture and cross-origin iframe support. The changes also update dependencies and improve configuration flexibility through environment variables.Responsive DOM capture and cross-origin iframe support:
isUnsupportedIframeSrc,getOrigin, andprocessFramewere introduced to support this. (src/main/java/io/percy/selenium/Percy.java)getResponsiveWidths), supporting both provided and config-driven widths, and allowing for optional minimum height and page reloads between widths (controlled by new environment variables). (src/main/java/io/percy/selenium/Percy.java) [1] [2]getWidthsForMultiDommethod in favor of the new approach, simplifying width configuration logic. (src/main/java/io/percy/selenium/Percy.java)Configuration and dependency updates:
PERCY_RESPONSIVE_CAPTURE_RELOAD_PAGEandPERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT, allowing users to control page reloads and minimum height during responsive capture. (src/main/java/io/percy/selenium/Percy.java)@percy/clidependency to version1.31.10inpackage.jsonto support new features. (package.json)Other improvements:
changeWindowDimensionAndWaitto safely handle temporary null states during page reloads. (src/main/java/io/percy/selenium/Percy.java)java.net.URIimport for URL parsing utilities. (src/main/java/io/percy/selenium/Percy.java)