locked
WebView1 to WebView2 (vb.net) RRS feed

  • Question

  • 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


    Sunday, September 13, 2020 7:30 AM

All replies

  • This is how it works. However it is adding a " {Quote} to the label. Which makes no sense to me. It should just display the innertext which doesn't have a " {quote}
    Sunday, September 13, 2020 1:52 PM
  • I ended up using .replace to remove the double quotes. But would prefer to know why they are even present. 
    Sunday, September 13, 2020 2:44 PM
  • Hi Innovators World Wide,

    Thank you for posting here.

    >>should it be just ...

    Yes, you can directly inject code into the method:

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

    Here's a document : Getting started with WebView2 in Windows Forms apps (Preview)

    >>However it is adding a " {Quote} to the label

    It seems to have something to do with the value that your script code get.

    Did you check the value of 'innerText' ?

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, September 14, 2020 7:55 AM