Home > Software design >  I am using AutoJsContext in geckobrowser with that I am using evaluate scrpit. But now i am using we
I am using AutoJsContext in geckobrowser with that I am using evaluate scrpit. But now i am using we

Time:11-23

I am using AutoJsContext in geckobrowser with that I am using evaluate scrpit and asble to get data. But now i am using webview2 is there a how can i get this.

Gecko browser:

using (AutoJSContext context = new AutoJSContext(browser.Window))
{
    var userIdResult = context
        .EvaluateScript("userId", (nsIDOMWindow)browser.Window.DomWindow);
}

Above is the code I use in gecko browser. now i need to get user id from webview2. Please help me in this issue

I am not able to get any alternative

CodePudding user response:

You can use CoreWebView2.ExecuteScriptAsync to inject script into the current top-level document of the WebView2 and receive the result as a JSON string. The method doesn't have a way to specify an execution context. Script is executed in the global context of the top-level document similar to running script in the console of DevTools in the browser.

For example something like the following:

var resultAsJSON = await coreWebView2.ExecuteScriptAsync('window.userId');
  • Related