Feat : Capture Cross Iframe and Responsive Capture Features#211
Feat : Capture Cross Iframe and Responsive Capture Features#211yashmahamulkar-bs wants to merge 16 commits intomasterfrom
Conversation
There was a problem hiding this comment.
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.
percy/snapshot.py
Outdated
| window._percyResizeHandler = () => { window.resizeCount++; }; | ||
| window.removeEventListener('resize', window._percyResizeHandler); |
percy/snapshot.py
Outdated
| 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) |
percy/snapshot.py
Outdated
| 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') |
percy/snapshot.py
Outdated
|
|
||
| # pylint: disable=too-many-arguments, too-many-branches, too-many-locals | ||
| def create_region( | ||
| *, |
tests/test_snapshot.py
Outdated
| @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' |
rahulXbrowserstack
left a comment
There was a problem hiding this comment.
Check test this thing once
We have
- iPhone 13 → width: 390px, height: 663px
- 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.
rahulXbrowserstack
left a comment
There was a problem hiding this comment.
also add the enhancement in the label of this PR, as this will ease to track the changes across versions
This pull request introduces significant improvements to the
percy/snapshot.pymodule, 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:
percy/snapshot.py)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:
percy/snapshot.py) [1] [2]percy/snapshot.py)Testing and Compatibility:
WebDriverclass from Selenium, improving compatibility with recent Selenium versions. (tests/test_driver_metadata.py)