C#C
C#3y ago
2 replies
Danielx64

❔ Needs some help with setting Webview2 option and fixing a known bug

Some background info:
I built an app that is currently in production that is pretty much a full screen browser with no address bar or anything like that. It was locked down with most options disabled. It's running well and all but I wanted to extend it a little and add tabs to it (since it was setup to only allow one instance of it running at a time).

After seeing this post on stackoverflow (https://stackoverflow.com/a/73087225/1129151), I decided to rebuild it, current source is here (https://github.com/Danielx64/PApps-player/).

I'm facing 2 issues:

In my current production version, I have the following code:

        var options = new CoreWebView2EnvironmentOptions
        {
            AllowSingleSignOnUsingOSPrimaryAccount = true,
            Language = $"{Globals.APP_REQUEST_LANG}"
        };

        if (!Directory.Exists(Globals.USER_DATA_FOLDER))
        {
            Directory.CreateDirectory(Globals.USER_DATA_FOLDER);
        }
        var environment = await CoreWebView2Environment.CreateAsync(null, Globals.USER_DATA_FOLDER, options).ConfigureAwait(true);

        await WebView.EnsureCoreWebView2Async(environment).ConfigureAwait(true);


Now for some reason I am unable to use that in my current project as it throws
CS1503    Argument 1: cannot convert from 'System.Runtime.CompilerServices.ConfiguredTaskAwaitable<Microsoft.Web.WebView2.Core.CoreWebView2Environment>' to 'Microsoft.Web.WebView2.Core.CoreWebView2Environment'
(even after editing a few lines to use wv instead and removing await)

Right now I am able to get something up and running with
WebView2 wv = new WebView2() { CreationProperties = new CoreWebView2CreationProperties() { UserDataFolder = userDataFolder } };

But I also need to set CoreWebView2EnvironmentOptions (AllowSingleSignOnUsingOSPrimaryAccount = true) and I am not sure how I can go about this.
Stack Overflow
I am using WebView2 in WPF and I am trying to simulate creating Tabs.
As a first step I am currently trying to simply create a new Tab. My idea for this is to add multiple WebView2 as children of a...
How to create Tabs using WebView2 in WPF?
Was this page helpful?