I have some C# code that shows how to enable Single Sign On in WebView2.
The TEdgeBrowser doesn't expose any of the properties that the C# code uses. In particular the interface defined in the Winapi.WebView2 unit for ICoreWebView2EnvironmentOptions doesn't have the functions for getting or setting AllowSingleSignOnUsingOSPrimaryAccount defined in it. I believe that this is because it was created from WebView2.tlb on 07/05/2020 whereas the property was added in the version released September 10, 2020.
What options do I have? Do I need to create my own version of WebView2 from the latest tlb and then duplicate the code in the Vcl.Edge unit to get a component with the SSO option enabled?
I don't need a visual component - I'd be happy to create the browser in code.
The C# code is:
private async void Form1_Load(object sender, EventArgs e)
{
var browser = new WebView2();
var options = new CoreWebView2EnvironmentOptions();
options.AllowSingleSignOnUsingOSPrimaryAccount = true;
var environment = await CoreWebView2Environment.CreateAsync(options: options).ConfigureAwait(false);
await browser.EnsureCoreWebView2Async(environment).ConfigureAwait(false);
Invoke((MethodInvoker)(() =>
{
browser.Dock = DockStyle.Fill;
this.Controls.Add(browser);
browser.Source = new Uri(https://example.com);
}));
}
CodePudding user response:
Try WebView4Delphi instead. WebView4Delphi is fully updated to the latest WebView2 version and it supports all the WebView2 interfaces.
You only have to add this line before the GlobalWebView2Loader.StartWebView2 call :
GlobalWebView2Loader.AllowSingleSignOnUsingOSPrimaryAccount := True;
The demos use the initialization section of the main unit to create GlobalWebView2Loader and set the properties. If you use the SimpleBrowser demo as a template for your application then you would have to add the previous line here.
That property in GlobalWebView2Loader is used for all the browsers that share the same ICoreWebView2Environment which is the default behavior.
In case you need to create a browser with an independent ICoreWebView2Environment then you have to set this property before the TWVBrowserBase.CreateBrowser call :
MyWVBrowser.AllowSingleSignOnUsingOSPrimaryAccount := True;
MyWVBrowser would be an instance of TWVBrowser.