Skip to content

Add responsive snapshot capture and CORS iframe support#124

Open
bhokaremoin wants to merge 11 commits intomainfrom
PPLT-4951-responsive-capture-and-cors-iframe-capture
Open

Add responsive snapshot capture and CORS iframe support#124
bhokaremoin wants to merge 11 commits intomainfrom
PPLT-4951-responsive-capture-and-cors-iframe-capture

Conversation

@bhokaremoin
Copy link

@bhokaremoin bhokaremoin commented Mar 2, 2026

Overview

Adds support for responsive snapshot capture, CORS iframe serialization, and cookie context capture to improve Percy snapshot fidelity and enable multi-width testing.


Key Features

1. Responsive Snapshot Capture

Enables capturing DOM snapshots at multiple viewport widths in a single call.

  • Added capture_responsive_dom() to iterate through configured widths
  • Fetches width configurations from Percy CLI via get_responsive_widths()
  • Supports environment variables: PERCY_RESPONSIVE_CAPTURE_MIN_HEIGHT, PERCY_RESPONSIVE_CAPTURE_RELOAD_PAGE, RESPONSIVE_CAPTURE_SLEEP_TIME

Usage:

percy_snapshot(page, "Homepage", responsiveSnapshotCapture=True, widths=[375, 768, 1280])

2. Cookie Context Capture

Snapshots now include page cookies to preserve authentication and session state.

  • Modified get_serialized_dom() to capture page.context.cookies()
  • DOM snapshot structure changed from string to object: {"html": "...", "cookies": [...]}

3. CORS Iframe Capture

Captures cross-origin iframe content previously inaccessible due to browser security.

  • Added process_frame() to serialize cross-origin frames
  • Injects Percy DOM script into each frame context
  • Sequential processing to avoid Playwright thread-safety issues

Code Changes

percy/screenshot.py:

  • is_percy_enabled()_is_percy_enabled() returns dict instead of string
  • Added get_serialized_dom() with CORS iframe support
  • Added responsive capture helpers
  • Unified logging via log() helper

Tests:

  • Added 59 test cases with 100% coverage
  • New file tests/test_init.py for wrapper tests

Infrastructure:

  • Added coverage enforcement (100% threshold)
  • Updated Playwright 1.28.*1.40.*
  • Updated Percy CLI to ^1.31.9-beta.5

Breaking Changes

  • DOM snapshot structure changed from string to object
  • Requires Percy CLI ^1.31.9-beta.5 or higher

@bhokaremoin bhokaremoin changed the title Pplt 4951 responsive capture and cors iframe capture Add responsive snapshot capture and CORS iframe support Mar 3, 2026
@bhokaremoin bhokaremoin marked this pull request as ready for review March 4, 2026 17:06
@bhokaremoin bhokaremoin requested a review from a team as a code owner March 4, 2026 17:06
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 enhances the Percy Playwright Python SDK’s snapshot fidelity and capabilities by adding multi-viewport (“responsive”) DOM snapshot capture, serializing cross-origin iframes, and including cookie context in snapshots. It also tightens CI quality gates by enforcing 100% coverage and updates Playwright/Percy CLI dependencies to support the new behavior.

Changes:

  • Add responsive snapshot capture (capture_responsive_dom, widths config lookup, resize/reload/sleep helpers).
  • Extend DOM snapshot payload to include cookies and cross-origin iframe snapshots (get_serialized_dom, process_frame).
  • Add/expand tests and enforce 100% coverage in CI; bump Playwright and Percy CLI versions.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
percy/screenshot.py Implements responsive capture, cookie capture, and CORS iframe serialization; introduces CLI logging helper.
percy/__init__.py Adds pragma: no cover handling for defensive import fallback.
tests/test_screenshot.py Updates/expands unit and integration tests for new snapshot payload and helpers.
tests/test_init.py Adds tests for backwards-compatible wrapper functions and version export.
requirements.txt Updates Playwright pin to 1.40.*.
package.json Updates @percy/cli dev dependency to ^1.31.9-beta.5.
development.txt Adds coverage dependency for local/CI reporting.
Makefile Adds coverage targets and enforces 100% coverage.
.github/workflows/test.yml Runs make test-coverage in CI.
.coveragerc Adds coverage configuration and fail-under threshold.

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

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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

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


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

Copy link

Copilot AI commented Mar 5, 2026

@bhokaremoin I've opened a new pull request, #126, to work on those changes. Once the pull request is ready, I'll request review from you.

… element is not found (#126)

* Initial plan

* Fix process_frame() to return None when iframe_data is missing or lacks percyElementId

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>
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

Copilot reviewed 9 out of 10 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (1)

percy/init.py:13

  • With 100% coverage enforced, only marking the except ImportError line as # pragma: no cover won’t exclude the fallback percy_snapshot() function body from coverage. In normal installs the try import succeeds, so lines 9-13 will remain uncovered and will fail coverage report --fail-under=100. Add # pragma: no cover to the fallback def/raise lines (or restructure so the whole fallback is excluded) to keep coverage deterministic.
except ImportError:  # pragma: no cover
    # This is defensive code in case percy_snapshot is not available
    def percy_snapshot(page, *a, **kw):
        raise ModuleNotFoundError(
            "[percy] `percy-playwright-python` package is not installed, "
            "please install it to use percy_snapshot command"
        )

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

…f github.com:percy/percy-playwright-python into PPLT-4951-responsive-capture-and-cors-iframe-capture
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants