Microsoft WebView2 Installation Announcement

Post Reply
rgdawson
Posts: 22
Joined: Tue Apr 10, 2018 11:05 pm

Microsoft WebView2 Installation Announcement

Post by rgdawson »

I develop a Microsoft Store application that currently deploys with CEF. I have redeveloped the app to replace CEF with WebView2. The Microsoft Store does not provide WebView2 package support (and likely do not intend to), so my application will need to check for WebView2 when it runs, (1) whether it is there at all, and (2) what version. If necessary, I need to be able to install/update the WebView2 Runtime at runtime from my application.

Unfortunately, the currently available Webview2 Runtime installer requires elevated privileges to install and that is a problem since Windows Store apps do not install/run with elevated privileges. The problem would be a non-privileged user gets updated to my new WebView2-based version of my app and then runs it, it could fail due to lack of WebView2 runtime, and then that user cannot install WebView2 runtime if needed. That's a problem.

However, there is good news. Microsoft will be updating their Webview2 runtime installer to be able to install the WebView2 runtime without requiring elevation. Details here --> https://github.com/MicrosoftEdge/WebView2Announcements/issues/37. Based on the announcement, it is supposed to be available around mid-December (any day now).

The next thing on my plate will be to figure out the best way to detect, then install/update, the WebView2 Runtime at runtime in my application.

The way I currently detect the presence/version of the WebView2 Runtime is to read the registry. I'm assuming I would just make this check before calling GlobalWebView2Loader. If I don't detect the presence/version I need, then I would set a flag, skip loading WebView2, and later once my main form is created do what I need to do (silently run the soon-to-be installer), then load WebView2 and continue on with my app. We'll see how it goes.

R Greg Dawson
User avatar
salvadordf
Posts: 4093
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Microsoft WebView2 Installation Announcement

Post by salvadordf »

The Loader has some functions to check if the WebView2 runtime is already installed :
https://github.com/salvadordf/WebView4Delphi/blob/11b6851854e481af792ff578b6630e203bfc4b0f/source/uWVLoader.pas#L498
https://github.com/salvadordf/WebView4Delphi/blob/11b6851854e481af792ff578b6630e203bfc4b0f/source/uWVLoader.pas#L660

If the app calls GlobalWebView2Loader.StartWebView2 with an empty GlobalWebView2Loader.BrowserExecPath and the runtime is not installed then GlobalWebView2Loader.StartWebView2 will return false and GlobalWebView2Loader.Status will be wvlsError.

I sill haven't implemented any functions to check the WebView binaries when the app uses the fixed version.
rgdawson
Posts: 22
Joined: Tue Apr 10, 2018 11:05 pm

Re: Microsoft WebView2 Installation Announcement

Post by rgdawson »

Thanks, I realized that after posting above, so I have been reading through some of the uWVLoaderSource.

BTW, I have a question about one thing not yet clear to me. How is TargetCompatibleBrowser both in WVLoader and WVBrowser used?

Let's say I don't need/call any functions added after 92.0.902.49. So, should I set TargetCompatibleBrowser to 92.0.902.49? How does the Loader and Browser us this value? I see it passed in the environment creation, but could not find what happens after that and what kind of error I would see if WebView is there but too old a version. Thanks.

R Greg Dawson
User avatar
salvadordf
Posts: 4093
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Microsoft WebView2 Installation Announcement

Post by salvadordf »

The GlobalWebView2Loader.TargetCompatibleBrowserVersion property is used to create the global environment that is normally used by all the browsers.

Only when you need an independent browser you would call TWVBrowserBase.CreateBrowser with aUseDefaultEnvironment set to false or aEnvironment set to nil and then TWVBrowserBase would create a new environment using the values of these properties :
  • TWVBrowserBase.TargetCompatibleBrowserVersion
  • TWVBrowserBase.AdditionalBrowserArguments
  • TWVBrowserBase.Language
  • TWVBrowserBase.AllowSingleSignOnUsingOSPrimaryAccount
  • TWVBrowserBase.BrowserExecPath
  • TWVBrowserBase.UserDataFolder

The API reference says this about TargetCompatibleBrowserVersion :
get_TargetCompatibleBrowserVersion

Specifies the version of the WebView2 Runtime binaries required to be compatible with your app.

public HRESULT get_TargetCompatibleBrowserVersion(LPWSTR * value)

This defaults to the WebView2 Runtime version that corresponds with the version of the SDK the app is using. The format of this value is the same as the format of the BrowserVersionString property and other BrowserVersion values. Only the version part of the BrowserVersion value is respected. The channel suffix, if it exists, is ignored. The version of the WebView2 Runtime binaries actually used may be different from the specified TargetCompatibleBrowserVersion. The binaries are only guaranteed to be compatible. Verify the actual version on the BrowserVersionString property on the ICoreWebView2Environment.
https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2environmentoptions?view=webview2-1.0.1054.31#get_targetcompatiblebrowserversion

I only did some simple tests with that property using wrong version values and the browser wasn't created at all.
rgdawson
Posts: 22
Joined: Tue Apr 10, 2018 11:05 pm

Re: Microsoft WebView2 Installation Announcement

Post by rgdawson »

My app will automatically perform a Webview2 EverGreen Runtime install if Webview2 initialization fails. It is tricky because my app is a store app and the user may not have admin privileges. If Webview2 is not there at all, then it is easy just to do a normal install using the bootstrap installer. But if it is there, but too old, then the only way to update it is with an all-user (elevated) install.

I have not been able to see TargetCompatibleBrowserVersion have any effect. I installed Windows 11 into a VM, since I know it starts off with an old version of Webview installed (90.x.x.x). No matter what I set TargetCompatibleBrowserVersion to, my app, with Webview4Delphi, the browser gets created fine. Of course, any calls to interfaces that don't exist in that version of Webview are ignored, which I expect.

I was just trying to determine what will happen when someone has the situation where they have an old evergreen runtime. I was trying to understand when Webview initialization would fail (in relation to the property) and when I would need to trigger an install from my app and whether it needs to be elevated or not. I'm thinking/wondering if this property applies when using a fixed install as opposed to an evergreen install

With evergreen, in most cases, Webview2 Runtime is either not there at all or it is fairly current. The only sure fire way I know to have an older version, at least for a little while is to not have the runtime installed, then upgrade to Windows 11, which puts an old version on there and does not update it until you actually run the Edge Browser and that triggers an update, or it eventually updates itself on its own. (As far as I can tell)

Thankfully, this particular case does not trigger a need to do an evergreen webview2 install. Attempting a per-user install to update an old all-user installation will, of course fail, so I am happy that Webvie4Delphi and my app will work with an old version, so I only have to trigger an install when Webview2 is completely missing, which I can do.

Thanks for your work. You are amazing.

R Greg Dawson
Post Reply