[Remote Inspection] Targeting heuristic may surface redundant elements in shadow roots#26941
Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom Apr 7, 2024
Merged
Conversation
Collaborator
|
EWS run on current version of this PR (hash 4c54674) Details |
rr-codes
approved these changes
Apr 7, 2024
megangardner
approved these changes
Apr 7, 2024
Member
Author
|
Thanks for the reviews! |
…s in shadow roots https://bugs.webkit.org/show_bug.cgi?id=272283 rdar://121251828 Reviewed by Megan Gardner and Richard Robinson. Currently, in the case where a targeted element is (or contains a) shadow root that encapsulates other candidates, we end up surfacing both the outer container element as well as the inner element in the shadow root as targeted elements to the WebKit client. Under normal circumstances, adding the outer element as a target should exclude the inner element from being a candidate. However, it fails in this case because the logic to enforce this invariant: ``` candidates.removeAllMatching([&](auto& candidate) { if (target.ptr() != candidate.ptr() && !target->contains(candidate)) return false; ``` ...uses `Node::contains(…)`, which does not account for shadow roots into account. Fix this by simply replacing this call with `containsIncludingShadowDOM`. Test: ElementTargeting.ContentInsideShadowRoot * Source/WebCore/page/ElementTargetingController.cpp: (WebCore::selectorsForTarget): There's also no point in surfacing a CSS selector to match content in shadow roots to the client. In a subsequent patch, we should provide an alternate means to resolve content inside of shadow roots that doesn't rely on (or relies on more than just) CSS selectors. (WebCore::ElementTargetingController::findTargets): * Tools/TestWebKitAPI/TestWebKitAPI.xcodeproj/project.pbxproj: * Tools/TestWebKitAPI/Tests/WebKitCocoa/ElementTargetingTests.mm: (TestWebKitAPI::TEST(ElementTargeting, ContentInsideShadowRoot)): * Tools/TestWebKitAPI/Tests/WebKitCocoa/element-targeting-4.html: Added. Add a new API test to cover this scenario. Canonical link: https://commits.webkit.org/277171@main
4c54674 to
dc0433c
Compare
Collaborator
|
Committed 277171@main (dc0433c): https://commits.webkit.org/277171@main Reviewed commits have been landed. Closing PR #26941 and removing active labels. |
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.
dc0433c
4c54674