WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

Blank window appears during initialization of first WebView2

Open nirdil opened this issue 1 year ago • 8 comments

What happened?

In a UWP app, when initializing the first off-screen WebView2, a blank window briefly appears for a few seconds before disappearing. I couldn’t reproduce this issue in a smaller sample project, so the conditions leading to this behavior are unclear. It seems to be a relatively recent bug introduced in the production Edge channel.

Additionally, this issue does not occur in the Edge Dev channel, which suggests it has been resolved in a later version. I’m unsure if this is a documented bug.

Can anyone confirm which version includes this fix and when it will be available in the production channel?

Importance

Important. My app's user experience is significantly compromised.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

129.0.2792.52

SDK Version

1.0.2839

Framework

WinUI2/UWP

Operating System

Windows 10

OS Version

10.0.19045

Repro steps

Not reproducible on a small sample project

Repros in Edge Browser

No, issue does not reproduce in the corresponding Edge version

Regression

Regression in newer Runtime

Last working version (if regression)

No response

AB#54137238

nirdil avatar Sep 25 '24 09:09 nirdil

I have the same problem. Here is a sample code (omitted XAML / WinUI 3).

using Microsoft.UI.Xaml;
using Microsoft.Windows.AppLifecycle;
using System;
using System.Diagnostics;
using System.Threading;

namespace Sample {
    public partial class App: Application {
        private Window? window;

        public App() {
            InitializeComponent();
        }

        protected override async void OnLaunched(LaunchActivatedEventArgs args) {
            var main = AppInstance.FindOrRegisterForKey("main");
            if (main.IsCurrent) {
                window = new MainWindow {};
                window.Activate();

                // some heavy process.
                Thread.Sleep(2000);
            } else {
                await main.RedirectActivationToAsync(AppInstance.GetCurrent().GetActivatedEventArgs());
                try {
                    Process.GetCurrentProcess().Kill();
                } catch {
                }
            } 
        }
    }

    public sealed partial class MainWindow: Window {
        public MainWindow() {
            InitializeComponent();
            InitializeWebView();
        }

        private async void InitializeWebView() {
            await WebView.EnsureCoreWebView2Async();
            WebView.Source = new("https://example.com/");
        }
    }
}

https://github.com/user-attachments/assets/0d2cb713-c0b7-4a71-af64-35481c22447c

naoki-yamamoto-ymh avatar Sep 25 '24 09:09 naoki-yamamoto-ymh

Thanks for opening this - I've added it as a bug on our side and we'll take a look right away. It's a good sign that it seems to be resolved in newer runtimes.

@naoki-yamamoto-ymh Are you able to see the issue in newer prerelease runtimes, like the current Dev channel? https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel?tabs=api#downloading-the-prerelease-sdk-and-a-preview-channel

champnic avatar Sep 26 '24 23:09 champnic

@champnic Thank you for your reply. I confirmed that this issue is resolved with Dev (130.0.2849.1) version!

naoki-yamamoto-ymh avatar Sep 27 '24 03:09 naoki-yamamoto-ymh

Hi @champnic - We have the same issue with Maui Blazor Windows.

Is there a way for us to test this with a newer version as well? Maui references Windows App SDK (1.6) - not sure how to switch to a later WebView2?

Thanks!

Thomr77 avatar Sep 27 '24 05:09 Thomr77

I just got a report that this issue is also affecting WebView4Delphi developers.

salvadordf avatar Sep 27 '24 10:09 salvadordf

We are seeing this issue in our Win App SDK 1.4 and 1.6 based applications in already installed applications. It started showing up around 3-4 days ago. I'm guessing there was an update to the edge browser that started to cause this behavior.

NicholasChrzan avatar Sep 27 '24 16:09 NicholasChrzan

@champnic Thank you for your reply. I confirmed that this issue is resolved with Dev (130.0.2849.1) version!

Thanks for confirming! 130 stable runtime should be deploying around mid-October.

Is there a way for us to test this with a newer version as well? Maui references Windows App SDK (1.6) - not sure how to switch to a later WebView2?

https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel?tabs=api#downloading-the-prerelease-sdk-and-a-preview-channel You'll need to download a prerelease channel of the Edge browser (Canary or Dev), and then switch the runtime search order. Using the registry key or environment variable are probably the easiest here: https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel?tabs=registry-key#switching-the-channel-search-order-recommended

champnic avatar Sep 27 '24 17:09 champnic

https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel?tabs=api#downloading-the-prerelease-sdk-and-a-preview-channel You'll need to download a prerelease channel of the Edge browser (Canary or Dev), and then switch the runtime search order. Using the registry key or environment variable are probably the easiest here: https://learn.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel?tabs=registry-key#switching-the-channel-search-order-recommended

This is working well with Maui Blazor Windows and Dev (130.0.2849.1) - adding in MauiProgram.CreateMauiApp() (or similar): Environment.SetEnvironmentVariable("WEBVIEW2_CHANNEL_SEARCH_KIND", "1");

@champnic - Thanks for this! Would you know if by around mid-October there will also be a Windows App SDK update to go with the 130 stable runtime?

Thomr77 avatar Sep 28 '24 03:09 Thomr77

For a reasonable workaround, set the webview's initial window size and position via the browser arguments e.g.:

Environment.SetEnvironmentVariable("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "--window-size=0,0 --window-position=20000,20000");

Place this close to your application start so that these arguments are set before the (first) webview is launched.

This is not perfect as a little bit of the window still pops in at the screen edge. But this way it is far less noticeable. Unfortunately, it is not possible to move the window fully outside of the view.

We have tested this with Maui Blazor but should work anywhere.

Thomr77 avatar Sep 30 '24 02:09 Thomr77

I'm experiencing the same issue in my UWP apps, and I've observed it in the WinUI 3 Gallery as well.

Runtime Channel - Stable release (WebView2 Runtime) Runtime Version - 129.0.2792.65 Operating System - Windows 11

I've attached a screen recording that had captured the flickering in my POC.

https://github.com/user-attachments/assets/53a15502-f60b-437a-a25e-e12a34c7b5f6

Aishwarya-Jeyaraj avatar Oct 01 '24 12:10 Aishwarya-Jeyaraj

This bug is quite severe, as all our released products with embedded WebView2 have suddenly started exhibiting strange behavior. Do you know when the fixed version will be released? We've also found that the issue occurs in Visual DirectComposition Mode, but not in Windowed Mode.

hangdongxue avatar Oct 01 '24 23:10 hangdongxue

As a serious product, this kind of bug is really BS. It affects billions of people.

vzhilong avatar Oct 04 '24 14:10 vzhilong

I updated the bug as I see now it's happening everywhere, and on each newly created WebView. I also have a feeling the WebView initialization time got deteriorated together with this glitch, but have not accurately tested it yet.

nirdil avatar Oct 07 '24 07:10 nirdil

@nirdil When you say "anywhere", you mean on frameworks outside of WinUI2/UWP? And it's still fixed when using a newer runtime?

champnic avatar Oct 07 '24 19:10 champnic

@champnic If you look above this bug was also flagged in a Delphi implementation, so it's a fairly safe to assume that this is happening outside of the Windows App SDK/WinUI3 and UWP/Winui2 frameworks.

NicholasChrzan avatar Oct 07 '24 19:10 NicholasChrzan

@champnic everywhere - in every framework, and yes it's still fixed in edge dev runtime.

nirdil avatar Oct 10 '24 08:10 nirdil