I can successfully fetch the inner text from google.com/index.html using the code below, but must click on a button. However, I would rather invoke an Await somehow to set the value of the sHTML string immediately after initbrowser(). However, I have tried using an Async Function "name" As Task, and awaited for sHTML to be set, but the CoreWebView2 is nothing (null), which throws an exception. Is there is a way to set the value of sHTML programatically right after I initialize the browser?
Code:Private Async Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Await initasync() Await initbrowser() End Sub Async Function initasync() As Task Await WebView21.EnsureCoreWebView2Async(Nothing) End Function Async Function initbrowser() As Task Await initasync() WebView21.CoreWebView2.Navigate("https://www.google.com/index.html") End Function Private Async Sub WebNavigation_Complete() Dim sHTML As String = Await WebView21.ExecuteScriptAsync("document.body.innerText;") End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click WebNavigation_Complete() End Sub




Reply With Quote
