Branch: refs/heads/main
Home: https://github.com/WebKit/WebKit
Commit: 3fd294fbb80690401533ceb0de45086cfc90b0fe
https://github.com/WebKit/WebKit/commit/3fd294fbb80690401533ceb0de45086cfc90b0fe
Author: Wenson Hsieh <[email protected]>
Date: 2026-03-29 (Sun, 29 Mar 2026)
Changed paths:
A Source/WebKit/Shared/FrameAndNodeIdentifiers.h
M Source/WebKit/Shared/TextExtractionToStringConversion.cpp
M Source/WebKit/Shared/TextExtractionToStringConversion.h
M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.h
M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.mm
M Source/WebKit/UIProcess/API/Cocoa/_WKTextExtractionInternal.h
M Source/WebKit/WebKit.xcodeproj/project.pbxproj
M Tools/TestWebKitAPI/Tests/WebKitCocoa/TextExtractionTests.mm
M Tools/WebKitTestRunner/Configurations/Base.xcconfig
Log Message:
-----------
[AutoFill Debugging] Add a way to provide a text extraction result as context
when creating an interaction
https://bugs.webkit.org/show_bug.cgi?id=310996
rdar://173600265
Reviewed by Abrar Rahman Protyasha.
Add a way for clients to pass in a previous `_WKTextExtractionResult` as
context, when creating a
`_WKTextExtractionInteraction`; this allows text-based interactions (which
search for extracted
text) to prioritize nodes that were previously extracted.
To achieve this, we:
1. Add an initializer for `_WKTextExtractionInteraction` that takes previous
text extraction
results as context.
2. Teach the text extraction item conversion code to build a side table of
extracted text to target
container node and frame IDs.
3. When performing a search-text-based interaction, we look up the table from
(2) to check if the
search text matches any nodes. If so, we additionally target the
corresponding node ID.
See below for more details.
Test: TextExtractionTests.ClickInteractionWithExtractionContext
* Source/WebKit/Shared/FrameAndNodeIdentifiers.h: Added.
Add a helper struct that represents a frame and node ID.
* Source/WebKit/Shared/TextExtractionToStringConversion.cpp:
(WebKit::TextExtractionAggregator::~TextExtractionAggregator):
(WebKit::TextExtractionAggregator::collectTextMapping):
Add a helper method to build up a map of trimmed text samples to lists of
enclosing node IDs (and
their corresponding frames), as we convert the intermediate text extraction
item tree into text.
(WebKit::populateJSONForItem):
(WebKit::addTextRepresentationRecursive):
Add calls to `collectTextMapping`.
* Source/WebKit/Shared/TextExtractionToStringConversion.h:
Add `textToContainerMap`, which keeps track of matching node IDs for each piece
of text that appears
in the extraction results.
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(createEmptyTextExtractionResult):
(-[WKWebView
_extractDebugTextWithConfigurationWithoutUpdatingFilterRules:assertionScope:completionHandler:]):
(-[WKWebView _convertToWebCoreInteraction:]):
Make this set a `nodeIdentifier` and `frameIdentifier` based on search text.
(-[WKWebView _performInteraction:completionHandler:]):
(-[WKWebView _describeInteraction:completionHandler:]):
Use the helper above when mapping `_WKTextExtractionInteraction` to
`TextExtraction::Interaction`.
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.h:
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtraction.mm:
(-[_WKTextExtractionResult
initWithWebView:textContent:filteredOutAnyText:shortenedURLs:textToContainerMap:]):
(-[_WKTextExtractionResult resolveContainerForSearchText:]):
Add a helper to look up enclosing container nodes, given search text.
(-[_WKTextExtractionInteraction initWithAction:]):
(-[_WKTextExtractionInteraction initWithAction:extractionContext:]):
Add an initializer that takes a prior `_WKTextExtractionResult` as context.
(-[_WKTextExtractionInteraction extractionContext]):
(-[_WKTextExtractionResult
initWithWebView:textContent:filteredOutAnyText:shortenedURLs:]): Deleted.
* Source/WebKit/UIProcess/API/Cocoa/_WKTextExtractionInternal.h:
* Source/WebKit/WebKit.xcodeproj/project.pbxproj:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/TextExtractionTests.mm:
(TestWebKitAPI::(TextExtractionTests, ClickInteractionWithExtractionContext)):
Add a test to exercise this change, by inserting a second button with identical
text after the
interaction has been created, and verifying that the original button is still
targeted.
* Tools/WebKitTestRunner/Configurations/Base.xcconfig:
Add `Source/WebKit/Shared/` to the header include paths, so
`_WKTextExtractionInternal.h` can be
imported in WebKitTestRunner.
Canonical link: https://commits.webkit.org/310185@main
To unsubscribe from these emails, change your notification settings at
https://github.com/WebKit/WebKit/settings/notifications