WebView1 to WebView2 (vb.net)

  • Thread starter Thread starter Innovators World Wide
  • Start date Start date
I

Innovators World Wide

Guest
With Webview1 becoming Obsolete (much quicker then the original "WebBrowser" component) I am making the switch from webview1 to webview2.

However ; just like transitioning from WebBrowser Control to WebView1 I had a lot to "learn" In this case I need to know how to change my "invoke script" to the newest format.

I know I have to

Imports Microsoft.Web.WebView2.Core.CoreWebView2

Then I know it has changed from InvokeScript to WebView.CoreWebView2.ExecuteScriptAsync , I know you can and should add the script to be executed on document ready. However my old style isn't working.

Old.

Dim name As String = Await WebView1.InvokeScriptAsync("eval", New String() {"document.getElementsByClassName('jsx-2835528490')[1].innerText.toString();"})


New

Dim name As String = Await WebView21.CoreWebView2.ExecuteScriptAsync("eval", New String() {"document.getElementsByClassName('jsx-2835528490')[1].innerText.toString();"})
I am being told it is

"Too Many Arguments" Which I understand (that is doesn't allow for the same number of arguments" however what can I change to make this work?


should it be just


WebView21.CoreWebView2.ExecuteScriptAsync("document.getElementsByClassName('jsx-2835528490')[1].innerText.toString();")


I'm missing something here.

Thank you everyone for your help

Continue reading...
 
Hello,
Yes, in the WebView2 the InvokeScript method is no longer available.
I found a post describing the way to use the ExecuteScriptAsync (Equivalent of WebBrowser.InvokeScript(String, Object[]) in WebView2)
In a nutshell you must put the full syntax of the called function (name and parameters) in he same string as ExecuteScriptAsync is accepting only one parameter.

Hope it helps.

By the way, I'm struggling with another issue.
The InvokeScript of the WebView is returning a string, which contains the value returned by the called function.
WebView2.ExecuteScriptAsync is returning a Task(of string) in which I do not find the value returned by the called function.
If you have an idea ;)

Thanks in advance.

Stéphane.
 
Back
Top