How to access the focused input field via JavaScript?

IWebView.ExecuteJavaScript() allows an application to run JavaScript to access HTML elements on the web page. The document.activeElement JavaScript API provides access to the currently focused HTML element, so if an <input> element is focused, it can be accessed through document.activeElement. For example, you can use IWebView.FocusedInputFieldChanged to detect when an input field is focused and then use document.activeElement to access its text, like this:

await webViewPrefab.WaitUntilInitialized();
webViewPrefab.WebView.FocusedInputFieldChanged += async (sender, eventArgs) => {
    if (eventArgs.Type == FocusedInputFieldType.Text) {
        // Use the `value` property for <input> and <textarea> elements.
        // Use `innerText` for elements with a contenteditable attribute.
        var inputFieldText = await webViewPrefab.WebView.ExecuteJavaScript("document.activeElement.value !== undefined ? document.activeElement.value : document.activeElement.innerText");
        Debug.Log("Input field text: " + inputFieldText);
    }
};

.