Conversation
- Add GET /percy/widths-config endpoint to compute responsive widths - Implement computeResponsiveWidths() in core utils for width/height calculation - Add getResponsiveWidths() SDK method to fetch computed widths - Mobile device widths include height, other widths are height-agnostic - Returns widths sorted in ascending order
- Add processCorsIframes and processCorsIframesInDomSnapshot utilities in utils.js - Add appendUrlSearchParam utility for adding query parameters to URLs - Integrate CORS iframe processing in snapshot method before validation - Process iframe resources and update HTML src attributes with width-aware URLs - Support both single domSnapshot object and array of domSnapshots
There was a problem hiding this comment.
Pull request overview
Adds core support for responsive-width computation (including mobile device height metadata) and centralizes CORS iframe snapshot processing so all SDKs can reuse the same logic.
Changes:
- Introduces
GET /percy/widths-configto compute a merged, deduped, sorted list of responsive widths (preserving mobile heights where applicable). - Moves CORS iframe extraction/rewriting into
@percy/coresnapshot flow via new utility helpers. - Adds
getResponsiveWidths()to@percy/sdk-utilsplus extensive tests for both features.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/core/src/api.js | Adds /percy/widths-config endpoint that returns computed responsive widths. |
| packages/core/src/utils.js | Adds URL param helper, CORS iframe processing utilities, and responsive-width computation helper. |
| packages/core/src/percy.js | Hooks CORS iframe processing into snapshot flow before validation. |
| packages/sdk-utils/src/get-responsive-widths.js | Adds SDK helper to call /percy/widths-config and return computed widths. |
| packages/sdk-utils/src/index.js | Exports getResponsiveWidths from sdk-utils. |
| packages/core/test/api.test.js | Tests for /percy/widths-config behavior across multiple scenarios. |
| packages/core/test/utils.test.js | Unit tests for computeResponsiveWidths, URL param helper, and CORS iframe processing. |
| packages/core/test/snapshot.test.js | Integration tests ensuring snapshots process CORS iframes and upload resources. |
| packages/sdk-utils/test/index.test.js | Tests sdk-utils getResponsiveWidths() request formatting and failure handling. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot open a new pull request to apply changes based on the comments in this thread |
|
@bhokaremoin I've opened a new pull request, #2123, to work on those changes. Once the pull request is ready, I'll request review from you. |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@bhokaremoin I've opened a new pull request, #2124, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@bhokaremoin I've opened a new pull request, #2125, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@bhokaremoin I've opened a new pull request, #2126, to work on those changes. Once the pull request is ready, I'll request review from you. |
…sInDomSnapshot (#2124) * Initial plan * fix: escape percyElementId before using in RegExp to prevent regex injection Co-authored-by: bhokaremoin <75439850+bhokaremoin@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bhokaremoin <75439850+bhokaremoin@users.noreply.github.com>
* Initial plan * Use Array.isArray check in getResponsiveWidths to ensure stable array return type Co-authored-by: bhokaremoin <75439850+bhokaremoin@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bhokaremoin <75439850+bhokaremoin@users.noreply.github.com>
…malformed input (#2125) * Initial plan * Add validation for malformed corsIframes entries in processCorsIframesInDomSnapshot Co-authored-by: bhokaremoin <75439850+bhokaremoin@users.noreply.github.com> * adding validation for widths as well --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: bhokaremoin <75439850+bhokaremoin@users.noreply.github.com> Co-authored-by: bhokaremoin <bhokaremoin@gmail.com>
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 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 9 out of 9 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@bhokaremoin I've opened a new pull request, #2127, to work on those changes. Once the pull request is ready, I'll request review from you. |
| type: 'array', | ||
| items: { type: 'string' } | ||
| }, | ||
| corsIframes: { |
There was a problem hiding this comment.
had to add it here, since post validate we can do domSnapshot.corsIframe.
Tried get it processed before validation, then faced the issue where for Js its domSnapshot and Python its dom_snapshot. adding handling for both didn't make sense
Overview
This PR introduces two major enhancements to the Percy CLI core package:
/percy/widths-configendpoint for responsive snapshot capture with mobile device height supportChanges
1. Responsive Widths Configuration Endpoint
New API Endpoint:
GET /percy/widths-configwidthsquery parameter (e.g.,?widths=375,1280)deviceDetailsExample Response:
{ "success": true, "widths": [ { "width": 375 }, { "width": 390, "height": 844 }, { "width": 428, "height": 926 }, { "width": 1920 } ] }SDK Integration:
getResponsiveWidths()function in@percy/sdk-utils2. CORS Iframe Processing (Moved from Playwright SDK)
Centralized CORS iframe handling in core:
@percy/playwright@percy/corefor reusability across all SDKscorsIframesarray in DOM snapshots before validationProcessing Logic:
corsIframesarraytext/htmlMIME typepercy_widthquery parameter to iframe URLs for responsive contextsrcattributes in HTML with processed URLscorsIframesproperty after processingNew Utility Functions:
processCorsIframes()- Handles single object or array of DOM snapshotsprocessCorsIframesInDomSnapshot()- Processes CORS iframes in single snapshotappendUrlSearchParam()- Safely appends query parameters to URLsBenefits:
Files Changed
Core Package
packages/core/src/api.js- New/percy/widths-configendpointpackages/core/src/percy.js- CORS iframe processing integrationpackages/core/src/utils.js- CORS processing & width computation utilitiesSDK Utils Package
packages/sdk-utils/src/get-responsive-widths.js- New utility (added)packages/sdk-utils/src/index.js- Export new functionTests
packages/core/test/api.test.js- 11 tests for widths-config endpointpackages/core/test/snapshot.test.js- 7 tests for CORS iframe processingpackages/core/test/utils.test.js- 37 tests for utility functionspackages/sdk-utils/test/index.test.js- 11 tests for getResponsiveWidthsTest Coverage
Breaking Changes
None - This is purely additive functionality.
Related Issues