Bug 227364 - iOS WKWebView findString not selecting and scrolling
Summary: iOS WKWebView findString not selecting and scrolling
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit2 (show other bugs)
Version: Other
Hardware: iPhone / iPad iOS 14
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-06-24 11:05 PDT by zero.griffin
Modified: 2021-07-01 11:06 PDT (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description zero.griffin 2021-06-24 11:05:08 PDT
Since iOS 14 WebKit supports findString, but there is no documentation whatsoever yet.

However on the WWDC Sessions Discover WKWebView enhancements they mention that is a basic functionality for "Find on Page", where you can find a string and the WebView will select it and scroll to center it.

It seems very easy to use and to be finding the string as I get a result of matchFound true, but there is no selection and there is no scrolling. Maybe I'm missing something?

This is the code I have tried:

let webView = WKWebView()
    
// ...
// after loading a website with the desired string on it.
// ...
    
webView.find("hello world") { result in
    print(result.matchFound) // true
}
Comment 1 Wenson Hsieh 2021-06-24 12:48:47 PDT
FWIW, the documentation does suggest that the matching range ought to be selected and scrolled into view:

```
/* @abstract Searches the page contents for the given string.
 @param string The string to search for.
 @param configuration A set of options configuring the search.
 @param completionHandler A block to invoke when the search completes.
 @discussion If the WKFindConfiguration is nil, all of the default WKFindConfiguration values will be used.
  A match found by the search is selected and the page is scrolled to reveal the selection.
  The completion handler is called after the search completes.
*/
- (void)findString:(NSString *)string withConfiguration:(nullable WKFindConfiguration *)configuration completionHandler:(void (^)(WKFindResult *result))completionHandler NS_REFINED_FOR_SWIFT WK_API_AVAILABLE(macos(11.0), ios(14.0));
```
Comment 2 Radar WebKit Bug Importer 2021-07-01 11:06:18 PDT
<rdar://problem/80034358>