---
title: "requestTextRects(for:withCompletionHandler:)"
framework: browserenginekit
role: symbol
role_heading: Instance Method
path: "browserenginekit/betextinput/requesttextrects(for:withcompletionhandler:)"
---

# requestTextRects(for:withCompletionHandler:)

Gathers context for the presentation of a text-related user interface.

## Declaration

```swift
func requestTextRects(for input: String, withCompletionHandler completionHandler: @escaping @Sendable ([UITextSelectionRect]) -> Void)
```

```swift
func requestTextRects(for input: String) async -> [UITextSelectionRect]
```

## Discussion

Discussion The system invokes your implementation of this method. The completion handler receives UITextSelectionRect instances for the substring nearest to the caret that matches the given input.

## See Also

### Requesting context

- [requestDocumentContext(_:completionHandler:)](browserenginekit/betextinput/requestdocumentcontext(_:completionhandler:).md)
- [requestTextContextForAutocorrection(completionHandler:)](browserenginekit/betextinput/requesttextcontextforautocorrection(completionhandler:).md)
