Skip to content

Feat : Capture Cross Iframe and Responsive Capture Features#211

Open
yashmahamulkar-bs wants to merge 16 commits intomasterfrom
PPLT-5027
Open

Feat : Capture Cross Iframe and Responsive Capture Features#211
yashmahamulkar-bs wants to merge 16 commits intomasterfrom
PPLT-5027

Conversation

@yashmahamulkar-bs
Copy link

This pull request introduces significant improvements to the percy/snapshot.py module, focusing on enhanced support for responsive and cross-origin iframe snapshotting, as well as better configuration via environment variables. The changes also include utility refactoring and improved test compatibility.

Responsive Snapshot and Cross-Origin Iframe Enhancements:

  • Added comprehensive support for capturing and stitching cross-origin iframes into DOM snapshots, including context management for iframe switching, serialization, and resource deduplication. (percy/snapshot.py)
  • Improved responsive snapshot capture by introducing new environment variable controls (PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT, PERCY_RESPONSIVE_CAPTURE_RELOAD_PAGE), fetching responsive widths from the Percy server, and handling window resizing and reload logic more robustly. (percy/snapshot.py) [1] [2]

Refactoring and Utility Improvements:

  • Refactored utility functions for environment variable parsing and window resize event handling, and restructured code to use context managers for safe iframe switching. (percy/snapshot.py) [1] [2]
  • Streamlined the main snapshotting logic to consistently inject the Percy DOM script and pass it to downstream functions, ensuring consistent behavior across both regular and responsive snapshots. (percy/snapshot.py)

Testing and Compatibility:

  • Updated test imports to use the correct WebDriver class from Selenium, improving compatibility with recent Selenium versions. (tests/test_driver_metadata.py)

Copy link

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 expands percy/snapshot.py to support cross-origin iframe stitching into DOM snapshots and improves responsive snapshot capture behavior/configuration (including new env-var toggles and fetching responsive widths from the Percy CLI). It also updates Selenium-related test imports/behavior for compatibility and adds targeted unit/integration-ish tests around the new functionality.

Changes:

  • Add cross-origin iframe capture + stitching into srcdoc, including safe iframe context switching and resource deduplication.
  • Rework responsive snapshot capture to fetch computed widths from /percy/widths-config, add reload/min-height controls, and refactor resize handling.
  • Update/extend tests to accommodate the new snapshot request patterns and Selenium WebDriver imports.

Reviewed changes

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

File Description
percy/snapshot.py Implements cross-origin iframe processing/stitching and refactors responsive snapshot capture to use CLI-provided widths and new env-var controlled behaviors.
tests/test_snapshot.py Updates snapshot assertions to be more robust against httpretty request ordering/duplication; adds new tests for responsive reload/min-height and iframe stitching.
tests/test_driver_metadata.py Updates Selenium WebDriver import/patch targets for improved compatibility with newer Selenium versions.

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

Comment on lines +308 to +309
window._percyResizeHandler = () => { window.resizeCount++; };
window.removeEventListener('resize', window._percyResizeHandler);
Copy link
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines +251 to +274
page_origin = _get_origin(driver.current_url)
iframes = driver.find_elements("tag name", "iframe")
if iframes and percy_dom_script:
processed_frames = []
for frame in iframes:
frame_src = frame.get_attribute('src')
if _is_unsupported_iframe_src(frame_src):
continue

try:
frame_origin = _get_origin(urljoin(driver.current_url, frame_src))
except Exception as e:
log(f"Skipping iframe \"{frame_src}\": {e}", "debug")
continue

if frame_origin == page_origin:
continue

result = process_frame(driver, frame, kwargs, percy_dom_script)
if result:
processed_frames.append(result)

if processed_frames:
dom_snapshot = stitch_cors_iframes(dom_snapshot, processed_frames)
Comment on lines +361 to +365
target_height = driver.execute_script(
f"return window.outerHeight - window.innerHeight + {min_height}")
log(
f'Calculated height for responsive capture using minHeight: {target_height}',
'debug')
Copy link
Author

Choose a reason for hiding this comment

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

fixed


# pylint: disable=too-many-arguments, too-many-branches, too-many-locals
def create_region(
*,
Copy link
Author

Choose a reason for hiding this comment

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

fixed

Comment on lines 389 to 391
@patch('selenium.webdriver.Chrome')
def test_posts_snapshots_to_the_local_percy_server_for_responsive_dom_chrome(self, MockChrome):
os.environ['RESONSIVE_CAPTURE_SLEEP_TIME'] = '1'
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 Add Cross Iframe features Feat : Add Cross Iframe features and Responsive Capture Features Mar 16, 2026
@yashmahamulkar-bs yashmahamulkar-bs changed the title Feat : Add Cross Iframe features and Responsive Capture Features Feat : Capture Cross Iframe and Responsive Capture Features Mar 16, 2026
Copy link

@rahulXbrowserstack rahulXbrowserstack left a comment

Choose a reason for hiding this comment

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

Check test this thing once
We have

  1. iPhone 13 → width: 390px, height: 663px
  2. Samsung S22 → width: 360px, height: 649px
    Now, when a mobile device is selected, its DOM will be captured at the specific device height.

If the same widths (390px or 360px) are used in desktop configs, then:

  • The default desktop height will be applied, OR
  • If minHeight is set and the PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT flag is enabled, then that minHeight will be used instead.

Copy link

@rahulXbrowserstack rahulXbrowserstack left a comment

Choose a reason for hiding this comment

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

also add the enhancement in the label of this PR, as this will ease to track the changes across versions

@yashmahamulkar-bs yashmahamulkar-bs added the ✨ enhancement New feature or request label Mar 18, 2026
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