How can I get the HTML or text from a web page?

With 3D WebView for Unity, you can access the HTML or text of web page by running JavaScript with IWebView.ExecuteJavaScript(). For example, here's how an application can retrieve the HTML for the entire web page:

// Wait until the prefab is initialized to access its WebView
await webViewPrefab.WaitUntilInitialized();
// Wait until the page has loaded to execute JavaScript
webViewPrefab.WebView.LoadProgressChanged += async (sender, eventArgs) => {
    if (eventArgs.Type == ProgressChangeType.Finished) {
        var html = await webViewPrefab.WebView.ExecuteJavaScript("document.documentElement.outerHTML");
        Debug.Log("HTML: " + html);
    }
};

However, it's more efficient to retrieve just the HTML or text that you need, so it's generally better to use more targeted JavaScript. For example, here's how an application can retrieve just the text for the first button:

var buttonText = await webViewPrefab.WebView.ExecuteJavaScript("document.getElementsByTagName('button')[0].innerText");
Debug.Log("Button text: " + buttonText);

The following JavaScript APIs are helpful for retrieving specific elements:

For information on debugging web content, see this article on remote debugging.