Skip to content

Feat : Adding Cross Iframe Feature#720

Open
yashmahamulkar-bs wants to merge 17 commits intomasterfrom
PPLT-5012
Open

Feat : Adding Cross Iframe Feature#720
yashmahamulkar-bs wants to merge 17 commits intomasterfrom
PPLT-5012

Conversation

@yashmahamulkar-bs
Copy link

@yashmahamulkar-bs yashmahamulkar-bs commented Mar 15, 2026

This pull request introduces significant improvements to cross-origin iframe handling and responsive DOM capture in the Selenium WebDriver integration, along with some code cleanup and dependency updates. The main focus is on enabling the serialization and stitching of cross-origin iframes into the main DOM snapshot, ensuring more accurate visual testing of pages with embedded content from different origins.

Cross-origin iframe handling:

  • Added a new captureSerializedDOM function that serializes the main DOM and then processes cross-origin iframes by capturing their DOM snapshots and injecting them back into the main snapshot using a new stitchCorsIframes function. This ensures that cross-origin iframe content is included in Percy snapshots by setting the srcdoc attribute on the relevant iframe elements.
  • Introduced a processFrame utility to handle the switching of frame contexts, execute serialization scripts, and robustly handle errors and context switching for cross-origin iframes.

Responsive DOM capture improvements:

  • Replaced the old getWidthsForMultiDOM function with utils.getResponsiveWidths, and updated the responsive DOM capture logic to support per-width height values, improving flexibility and accuracy for responsive snapshots. [1] [2] [3]

Dependency updates:

  • Updated dependencies to the latest alpha versions of @percy/sdk-utils and @percy/cli in package.json for compatibility with new features and bug fixes.

Other improvements:

  • Added explicit logging when responsive capture is disabled due to deferUploads being true, improving debuggability.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances the Selenium WebDriver Percy integration by adding cross-origin iframe DOM capture + stitching into the main DOM snapshot, and by updating responsive snapshot capture to use utils.getResponsiveWidths() (supporting per-width heights). It also adds unit tests around these behaviors and updates Percy-related dependencies.

Changes:

  • Added cross-origin iframe processing (captureSerializedDOM + processFrame) and stitching via exported stitchCorsIframes().
  • Updated responsive DOM capture to use utils.getResponsiveWidths() and support { width, height } tuples.
  • Updated @percy/sdk-utils and @percy/cli versions and added extensive new tests.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 7 comments.

File Description
index.js Adds cross-origin iframe DOM serialization/stitching; switches responsive widths logic to utils.getResponsiveWidths(); adds logging when responsive capture is disabled due to deferUploads.
test/index.test.mjs Adds tests for cross-origin iframe processing, iframe src filtering, and responsive width/height handling.
package.json Updates Percy dependency versions to 1.31.10-alpha.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

describe('stitchCorsIframes', () => {
let switchSpies;
let frameElement;
let iframeDriver;
Comment on lines +947 to +955
let callCount = 0;
return {
getCurrentUrl: jasmine.createSpy().and.returnValue(Promise.resolve('https://host.example.com/')),
findElements: jasmine.createSpy().and.returnValue(Promise.resolve([frameElement])),
switchTo: jasmine.createSpy().and.returnValue(switchSpies),
executeScript: jasmine.createSpy('executeScript').and.callFake(async () => {
callCount++;
if (callCount === 1) return { domSnapshot: { html: mainHtml, resources: [] } };
return iframeHtml ? { html: iframeHtml, resources: [] } : { resources: [] };
});

describe('captureSerializedDOM - iframe src filtering', () => {
let baseDriver;
Comment on lines +107 to +109
const currentUrl = new URL(await driver.getCurrentUrl());
const iframes = await driver.findElements({ css: 'iframe' });
const processedFrames = [];
index.js Outdated
Comment on lines +149 to +159
function stitchCorsIframes(domSnapshot, processedFrames) {
let html = domSnapshot.html;
for (const { iframeData: { percyElementId }, iframeSnapshot } of processedFrames) {
if (!iframeSnapshot?.html) continue;
const srcdocValue = iframeSnapshot.html
.replace(/&/g, '&')
.replace(/"/g, '"');
html = html.replace(
new RegExp(`(<iframe\\b[^>]*?data-percy-element-id="${percyElementId}"[^>]*?)(/?>)`, 's'),
`$1 srcdoc="${srcdocValue}">`
);
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR enhances Percy’s Selenium WebDriver DOM capture to better include cross-origin iframe content in serialized DOM snapshots, while also improving responsive snapshot capture width/height handling and adding unit tests.

Changes:

  • Added cross-origin iframe serialization flow (captureSerializedDOM + processFrame) and HTML stitching via exported stitchCorsIframes().
  • Updated responsive DOM capture to use utils.getResponsiveWidths() with per-width height support.
  • Added extensive Jasmine tests around iframe stitching/switching and responsive capture behavior; updated Percy dependencies to alpha versions.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
index.js Implements cross-origin iframe capture + stitching, responsive width/height updates, and new logging/export.
test/index.test.mjs Adds integration/unit tests for iframe processing/stitching and responsive capture resizing behavior.
package.json Updates @percy/sdk-utils and @percy/cli versions to 1.31.10-alpha.0.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

index.js Outdated
Comment on lines +161 to +176
for (const { iframeData: { percyElementId }, iframeSnapshot } of processedFrames) {
if (!iframeSnapshot?.html) continue;
const srcdocValue = iframeSnapshot.html
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;');
const escapedId = escapeRegExp(percyElementId);
const iframeRegex = new RegExp(
`(<iframe\\b[^>]*?data-percy-element-id="${escapedId}"[^>]*?)(/?>)`,
's'
);
html = html.replace(
iframeRegex,
(match, iframeStart, iframeEnd) => `${iframeStart} srcdoc="${srcdocValue}">`
);
}
return { ...domSnapshot, html };
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@yashmahamulkar-bs yashmahamulkar-bs changed the title Enhance cross-iframe feature with lint fixes and unit tests Feat : Adding Cross Iframe Feature Mar 18, 2026
@yashmahamulkar-bs yashmahamulkar-bs added the ✨ enhancement New feature or request label Mar 18, 2026
"name": "@percy/selenium-webdriver",
"description": "Selenium client library for visual testing with Percy",
"version": "2.2.5",
"version": "2.2.6-alpha.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update tag as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

✨ enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants