Add support for pseudo-class enabled elements in DOM serialization#2046
Merged
this-is-shivamsingh merged 16 commits intomasterfrom Dec 4, 2025
Merged
Add support for pseudo-class enabled elements in DOM serialization#2046this-is-shivamsingh merged 16 commits intomasterfrom
this-is-shivamsingh merged 16 commits intomasterfrom
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This pull request adds support for pseudo-class enabled elements in DOM serialization by introducing a new feature that captures computed styles of specified elements and applies them as inline styles with !important declarations in the serialized DOM. The feature allows elements to be selected by ID or XPath and preserves their styles during serialization.
Key changes:
- New
serialize-pseudo-classes.jsmodule for marking and serializing pseudo-class enabled elements - Integration into the DOM serialization pipeline with pre-clone marking and post-clone style injection
- Configuration schema additions to support
pseudoClassEnabledElementsoption withidandxpatharrays
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/dom/src/serialize-pseudo-classes.js | New module implementing element selection (by ID/XPath), marking with data attributes, and computed style serialization with !important injection |
| packages/dom/src/serialize-dom.js | Integrates pseudo-class serialization into the main DOM serialization flow: marks elements before cloning and processes them after element serialization |
| packages/core/src/page.js | Propagates pseudoClassEnabledElements configuration parameter through the snapshot process to the serialization layer |
| packages/core/src/discovery.js | Adds debug logging for the pseudoClassEnabledElements configuration option |
| packages/core/src/config.js | Defines JSON schema for pseudoClassEnabledElements configuration with id and xpath array properties |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
prklm10
approved these changes
Dec 2, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of the change:
This pull request introduces support for serializing pseudo-class enabled elements in the DOM snapshot process. It allows users to specify elements (by ID, class name, or XPath) whose computed styles—including those affected by pseudo-classes—should be captured and inlined into the snapshot. This ensures more accurate visual testing of states like
:hoveror:active. The changes include updates to configuration schemas, the serialization pipeline, and the addition of a new module to handle pseudo-class serialization.Pseudo-class serialization support:
pseudoClassEnabledElementsto both the config and snapshot schemas, allowing users to specify elements byid,className, orxpathfor pseudo-class serialization. [1] [2]pseudoClassEnabledElementsoption throughout the snapshot pipeline, including passing it through the snapshot process and logging it in debug output. [1] [2] [3] [4]DOM serialization pipeline enhancements:
serialize-dom.jsto extract thepseudoClassEnabledElementsoption, mark relevant elements before cloning, and inject computed styles as inline CSS after cloning for accurate pseudo-class rendering. [1] [2] [3]New pseudo-class serialization module:
serialize-pseudo-classes.jsmodule, which:Test and ignore file updates:
.semgrepignore.These changes collectively enable more accurate visual testing of dynamic element states by capturing and replaying pseudo-class styles in DOM snapshots.