Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: 6208d85450b164ab80406f4964fa6db9a14d21ad
      
https://github.com/WebKit/WebKit/commit/6208d85450b164ab80406f4964fa6db9a14d21ad
  Author: Wenson Hsieh <[email protected]>
  Date:   2026-01-08 (Thu, 08 Jan 2026)

  Changed paths:
    M Source/WebCore/Sources.txt
    M Source/WebCore/WebCore.xcodeproj/project.pbxproj
    M Source/WebCore/page/ElementTargetingController.cpp
    M Source/WebCore/page/ElementTargetingController.h
    A Source/WebCore/page/ElementTargetingTypes.cpp
    M Source/WebCore/page/ElementTargetingTypes.h
    M Source/WebCore/page/EventHandler.cpp
    M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
    M Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h
    M Source/WebKit/UIProcess/WebFrameProxy.cpp
    M Source/WebKit/UIProcess/WebFrameProxy.h
    M Source/WebKit/WebProcess/WebPage/WebFrame.cpp
    M Source/WebKit/WebProcess/WebPage/WebFrame.h
    M Source/WebKit/WebProcess/WebPage/WebFrame.messages.in
    M Tools/TestWebKitAPI/Tests/WebKitCocoa/TextExtractionTests.mm

  Log Message:
  -----------
  [AutoFill Debugging] Add a way for clients to extract and resolve DOM 
selector paths from _WKJSHandle
https://bugs.webkit.org/show_bug.cgi?id=305140
rdar://167717829

Reviewed by Abrar Rahman Protyasha.

Add support for two new methods on `WKWebView`:

```
- (void)_getSelectorPathDataForNode:(_WKJSHandle *)node completionHandler:(void 
(^)(NSData *))completionHandler;
- (void)_getNodeForSelectorPathData:(NSData *)data completionHandler:(void 
(^)(_WKJSHandle *))completionHandler;
```

...which can be used to convert a `_WKJSHandle` that points to a DOM node into 
a serialized data
blob representing CSS selector paths that can be used to reidentify the "same" 
(or similar) DOM node
upon subsequent page loads. See below for more details.

Test: TextExtractionTests.ResolveTargetNodeFromSelectorData

* Source/WebCore/Sources.txt:
* Source/WebCore/WebCore.xcodeproj/project.pbxproj:

Drive-by fix: remove stale (broken) references to `PaintTimingData.{h|cpp}` in 
the Xcode project.

* Source/WebCore/page/ElementTargetingController.cpp:
(WebCore::ElementTargetingController::elementFromSelectors):
(WebCore::ElementTargetingController::selectorsForElement):
(WebCore::ElementTargetingController::findElementFromSelectors):

Refactor `ElementTargetingController`, such that the abilities to map between 
elements/selectors are
exposed as public static methods.

* Source/WebCore/page/ElementTargetingController.h:
* Source/WebCore/page/ElementTargetingTypes.cpp: Added.
(WebCore::serializeTargetedElementSelectors):
(WebCore::deserializeTargetedElementSelectors):

Add helper methods to convert selector path sets into opaque data, and vice 
versa.

* Source/WebCore/page/ElementTargetingTypes.h:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _getSelectorPathDataForNode:completionHandler:]):
(-[WKWebView _getNodeForSelectorPathData:completionHandler:]):

Add the new SPI entry points.

* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/WebFrameProxy.cpp:
(WebKit::WebFrameProxy::getSelectorPathsForNode):
(WebKit::WebFrameProxy::getNodeForSelectorPaths):
* Source/WebKit/UIProcess/WebFrameProxy.h:
* Source/WebKit/WebProcess/WebPage/WebFrame.cpp:
(WebKit::nodeFromJSHandleIdentifier):

Pull this logic out into a separate static helper function, so that we can 
invoke it in
`getNodeForSelectorPaths` as well.

(WebKit::WebFrame::takeSnapshotOfNode):
(WebKit::WebFrame::getSelectorPathsForNode):
(WebKit::WebFrame::getNodeForSelectorPaths):
* Source/WebKit/WebProcess/WebPage/WebFrame.h:
* Source/WebKit/WebProcess/WebPage/WebFrame.messages.in:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/TextExtractionTests.mm:
(-[WKWebView synchronouslyGetSelectorPathDataForNode:]):
(-[WKWebView synchronouslyGetNodeForSelectorPathData:]):
(TestWebKitAPI::TEST(TextExtractionTests, ResolveTargetNodeFromSelectorData)):

Add a new API test that first obtains selector path data for a given element 
using text extraction,
and then (in a newly created web view that loads the same page) resolves the 
selector paths to a
node handle, which is then used to extract text in the new web view.

Canonical link: https://commits.webkit.org/305344@main



To unsubscribe from these emails, change your notification settings at 
https://github.com/WebKit/WebKit/settings/notifications

Reply via email to