Skip to content

Add closed shadow DOM capture via CDP#136

Open
aryanku-dev wants to merge 5 commits intomainfrom
PER-7292
Open

Add closed shadow DOM capture via CDP#136
aryanku-dev wants to merge 5 commits intomainfrom
PER-7292

Conversation

@aryanku-dev
Copy link
Copy Markdown

Summary

  • Add expose_closed_shadow_roots() using CDP to discover and expose closed shadow roots
  • Add _walk_nodes() helper for CDP DOM tree traversal
  • Add 6 unit tests covering tree walking, non-Chromium skip, CDP errors

Ported from percy/percy-playwright#609

Test plan

  • Unit tests pass
  • Verify no regression on pages without shadow DOM

🤖 Generated with Claude Code

Use CDP to discover closed shadow roots before DOM serialization.
Closed shadow roots are inaccessible from JS (element.shadowRoot === null),
but CDP's DOM domain can pierce them. We resolve each closed shadow root
to a JS object and store it in a WeakMap that PercyDOM.serialize() reads.

- Add expose_closed_shadow_roots() using CDP session
- Add _walk_nodes() helper to traverse CDP DOM tree
- Skip iframe contentDocument nodes (cross-frame not yet supported)
- Non-fatal: catches exceptions for non-Chromium browsers and CDP errors
- Called after PercyDOM injection, before DOM serialization
- Add tests for walk_nodes, non-Chromium skip, CDP errors, closed roots

Ported from percy/percy-playwright#609

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@aryanku-dev aryanku-dev requested a review from a team as a code owner April 20, 2026 18:47
aryanku-dev and others added 4 commits April 21, 2026 00:22
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Single try/except/finally so non-Chromium path (cdp_session=None)
exercises the finally's False branch for 100% coverage.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The finally block's if/except branches are exercised by tests
(test_expose_non_chromium_browser and test_expose_detach_error_suppressed)
but coverage.py's branch analysis doesn't track them through
try/except/finally control flow correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

1 participant