Branch: refs/heads/main
  Home:   https://github.com/WebKit/WebKit
  Commit: c7b96b676c378ff2df1de077acbd349d74a809b6
      
https://github.com/WebKit/WebKit/commit/c7b96b676c378ff2df1de077acbd349d74a809b6
  Author: Wenson Hsieh <[email protected]>
  Date:   2026-06-29 (Mon, 29 Jun 2026)

  Changed paths:
    M Source/WebCore/page/text-extraction/TextExtraction.cpp
    M Source/WebCore/page/text-extraction/TextExtractionTypes.h
    M Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in
    M Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm
    M Source/WebKit/UIProcess/TextExtractionCache.cpp
    M Source/WebKit/UIProcess/TextExtractionCache.h
    M Source/WebKit/WebProcess/WebPage/WebFrame.cpp
    M Tools/TestWebKitAPI/Tests/WebKit/WKWebView/TextExtractionTests.mm

  Log Message:
  -----------
  [Text Extraction] Make it possible for clients to target elements using stale 
node UIDs
https://bugs.webkit.org/show_bug.cgi?id=318078
rdar://180873603

Reviewed by Abrar Rahman Protyasha.

Build on top of the changes in 315981@main, to complete the heuristic and map 
stale element `uid`s
to elements in the current DOM. See below for more details.

Test: TextExtractionTests.InteractionRemapsStaleNodeIdentifier

* Source/WebCore/page/text-extraction/TextExtraction.cpp:
(WebCore::TextExtraction::interactionDescription):

See changes in `_describeInteraction` below.

* Source/WebCore/page/text-extraction/TextExtractionTypes.h:
* Source/WebKit/Shared/WebCoreArgumentCoders.serialization.in:
* Source/WebKit/UIProcess/API/Cocoa/WKWebView.mm:
(-[WKWebView _convertToWebCoreInteraction:nodeIdentifier:]):
(-[WKWebView _performInteraction:completionHandler:]):

When performing an interaction, if the interaction fails due to the element 
being disconnected or
otherwise stale, try to resolve the `uid` against older cached extraction 
results and remap it to a
newer `uid` if the context in and around that newer `uid` matches the context 
in and around the
stale `uid`.

(-[WKWebView 
_performInteraction:inFrame:actionType:nodeIdentifier:staleNodeNote:shouldResolveStaleNodeIdentifier:completionHandler:]):
(-[WKWebView _describeInteraction:completionHandler:]):
(-[WKWebView 
_describeInteraction:inFrame:nodeIdentifier:staleNodeNote:shouldResolveStaleNodeIdentifier:completionHandler:]):

Similar to the above; this time, we additionally add a flag to the 
`interactionDescription` result
that indicates whether the element being described is disconnected from the 
DOM; if so, then we fall
back to re-resolving it.

(-[WKWebView _convertToWebCoreInteraction:]): Deleted.
* Source/WebKit/UIProcess/TextExtractionCache.cpp:
(WebKit::TextExtractionCache::add):
(WebKit::TextExtractionCache::resolve const):

Search for stale node UIDs that appear in any cached results, not just the 
oldest one. This ensures
that even if the stale element appears in different contexts, we'll still be 
able to resolve it as
long as any of the contexts are similar enough to the latest extraction result.

* Source/WebKit/UIProcess/TextExtractionCache.h:
* Tools/TestWebKitAPI/Tests/WebKit/WKWebView/TextExtractionTests.mm:
(TestWebKitAPI::TEST(TextExtractionTests, 
InteractionRemapsStaleNodeIdentifier)):

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



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

Reply via email to