Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BlazorWebView: Allow for WPF and WinForms WebView2 Custom Startup Settings and Fixed Distribution Mode #5086

Closed

Conversation

MichaelPeter
Copy link

Description of Change

Currently it is not possible to use WebView2 Fixed Distribution mode since the Blazor WebView creates a custom Environment which cannot be modified. This also prevents:
See WebViewInitialize

  • Using Edge Canary Builds.
  • Activating Beta features like --unsafe-web-gpu
  • Using startup flags in general
  • Starting an FPS Counter.
  • and many more...

This is a implementation which was implemented based on a suggestion in the issue.

Other issues related to that
#2548

Uncarlities: The WPF Version used a EventHandler<> Delegate Depedency Property for ExternalNavigationStarting. It is not clear why no WPF RoutedEvent is used for events. In WinForms it is also an EventHandler<> delegate, even thought for Windows Forms Controls, events are also more common.

The new InitializingWebView is an RoutedEvent in WPF. In Windows Forms it is an EventHandler Delegate Property.

Could change InitializingWebView after an explanation also to EventHandler<> in WPF too. But wanted to leave it like that will I know why an EventHandler is use.

Issues Fixed

#3861
#2548

@MichaelPeter MichaelPeter requested a review from a team as a code owner March 7, 2022 01:20
@dnfadmin
Copy link

dnfadmin commented Mar 7, 2022

CLA assistant check
All CLA requirements met.

@jsuarezruiz jsuarezruiz added the area/blazor 🕸️ Blazor Hybrid / Desktop, BlazorWebView label Mar 7, 2022
@SteveSandersonMS
Copy link
Member

Thanks for the contribution, @MichaelPeter!

As it stands, I'm not absolutely sure we intend to include APIs for this in the initial release. We made a specific plan to keep "fixed distribution" mode out of scope for the first release, as it creates a lot of potentially different deployment combinations that we're not in a position to document, support, or debug (if people hit issues) while working on such a short timescale. We were expecting to add this in the next release when we have more flexibility around support.

As far as I'm aware, it is technically possible to achieve this already without needing a supported API from dotnet/maui. That is, the WebView2 control looks for the following environment variables documented here:

WEBVIEW2_BROWSER_EXECUTABLE_FOLDER
WEBVIEW2_USER_DATA_FOLDER
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS
WEBVIEW2_RELEASE_CHANNEL_PREFERENCE

... which can be used to control the things it looks like you need. You can assign values to these variables from your .NET code during application startup before the WebView2 control is instantiated.

Could you let us know if this is technically sufficient for your goals? I know it's more obscure than having a supported API inside the BlazorWebView code, of course!

@MichaelPeter
Copy link
Author

Thank you @SteveSandersonMS for the hint,

I was aware of WEBVIEW2_RELEASE_CHANNEL_PREFERENCE, but not the other environment variables - I tested it in my scenario and it worked.

As a hint:
The only thing which is still missing are these properties, but these are not importaint of my scenario:

            e.CoreWebView2EnvironmentOptions.AllowSingleSignOnUsingOSPrimaryAccount = true;
            e.CoreWebView2EnvironmentOptions.Language = "DE-DE";
            e.CoreWebView2EnvironmentOptions.TargetCompatibleBrowserVersion 

But AllowSingleSignOnUsingOSPrimaryAccount I could imagine is importaint for azure developers. I did not find environment variables for them. (https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/webview2-idl?view=webview2-1.0.1150.38)

As TargetCompatibleBrowserVersion a webgpu compatible version is installed, but ensureing a compatible version can also be checked differently, even if more diffcult.

@SteveSandersonMS
Copy link
Member

Thanks @MichaelPeter. I've filed #5512 to follow up on the AllowSingleSignOnUsingOSPrimaryAccount requirement.

@Eilon
Copy link
Member

Eilon commented Apr 15, 2022

Hi @MichaelPeter , with PR #5802 merged, I think there are now enough events and hooks to customize various WebView2 startup settings (and similar on other platforms in .NET MAUI).

Is it safe to close this PR now because there is enough functionality?

@mattleibow mattleibow added this to the 6.0.300-servicing milestone May 11, 2022
@jfversluis
Copy link
Member

As per Eilon's comment, closing this one. @MichaelPeter thank you so much for all your efforts. If you believe this is still necessary please let us know and we'll gladly reopen this and see if we can get this merged.

@jfversluis jfversluis closed this Jun 16, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Dec 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/blazor 🕸️ Blazor Hybrid / Desktop, BlazorWebView
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants