dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

WebView causes empty window popup and closes immediately #24933

Open jhastingsiii opened 1 week ago

jhastingsiii commented 1 week ago

Description

This only started happening recently without any code changes, guessing maybe a browser or windows update has caused the problem? There never used to be any kind of flickering popup. If you don't set the source property on the web view, the popup doesn't occur. The popup is hard to see with the default window size, make the window size smaller to see it easier.

Steps to Reproduce

  1. New MAUI app
  2. New Page with a web view that has hardcoded source content
  3. Navigate to the new page

https://github.com/jhastingsiii/busted-maui-webview

Link to public reproduction project repository

No response

Version with bug

8.0.91 SR9.1

Is this a regression from previous behavior?

Yes, this used to work in .NET MAUI

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

No response

Did you find any workaround?

No

Relevant log output

No response

drasticactions commented 1 week ago

Can you please make a small repro project showing this? It makes it easier to establish the issue from a shared context in case anyone else can't.

ITaluone commented 1 week ago

I think I have a related problem. I am developing two WinUI apps which both have approximately the same setup.

My app setup is as follows (the same for both):

  builder.ConfigureLifecycleEvents(lifecycle =>
      {
#if WINDOWS
          lifecycle.AddWindows(lifecycleBuilder => lifecycleBuilder
              .OnPlatformMessage((window, _) =>
              {
                  if (!(IsStarting && ps.StartInSystemTray())) return;

                  GetAppWindow(window);

                  _appWindow.Hide();
              })
              .OnVisibilityChanged((_, args) =>
              {
                  if (IsStarting && ps.StartInSystemTray())
                  {
                      DisableStarting();
                      return;
                  }

                  if (!ps.Get<bool>(StorageKey.MinimizeToSystemTray)) return;

                  if (IsClosing || args.Visible)
                  {
                      App.ResizeSave();
                      return;
                  }

                  MinimizeToTray();
              })
              .OnWindowCreated(window =>
              {
                  // window.ExtendsContentIntoTitleBar = true; // https://github.com/dotnet/maui/issues/18773
                  GetAppWindow(window);

                  if (ps.StartAppMaximized() && _appWindow.Presenter is OverlappedPresenter p) p.Maximize();

                  _appWindow.Closing += (_, e) =>
                  {
                      e.Cancel = true;

                      if (ps.Get<bool>(StorageKey.DoNotQuitApp) && !ForceClose)
                      {
                          MinimizeToTray();
                          return;
                      }

                      SetClosing();
                      Application.Current?.Quit();
                  };
              }));
#endif
      });

In the past, this setup prevents the app window to show at all on startup (just makes the systray icon (with H.NotifyIcon.Maui, btw) and nothing else, until the user opens the app by icon click. This is the setup both share.

But since today or so (I can not tell since when exactly, because I stumbled upon this today the first time) a blank window pops up, size is approx. window height and the width approx. width/2.

What I tried:

Conclusion

I can not tell what had changed, but it seems that MAUI is not the only actor in the story, because when I start the already released and deployed apps it works as it should. Probably a race condition with WASDK/MAUI or .NET SDK or WebView2 runtime.

Edit: I managed to stop with a break point when the popup is open.

2024-09-26_14-38-34.zip (this is a short screen cast, I didn't manage to upload the MP4 directly...

What really strange is: I can click behind it and open the context menu from a desktop icon (as example).

jhastingsiii commented 1 week ago

Can you please make a small repro project showing this? It makes it easier to establish the issue from a shared context in case anyone else can't.

Yes, it wouldn't let me attach it to the original ticket for some reason, here it is. MauiApp1.zip

jhastingsiii commented 1 week ago

Hi @jhastingsiii. We have added the "s/needs-repro" label to this issue, which indicates that we require steps and sample code to reproduce the issue before we can take further action. Please try to create a minimal sample project/solution or code samples which reproduce the issue, ideally as a GitHub repo that we can clone. See more details about creating repros here: https://github.com/dotnet/maui/blob/main/.github/repro.md

This issue will be closed automatically in 7 days if we do not hear back from you by then - please feel free to re-open it if you come back to this issue after that time.

Broken bot? Not only did I provide the steps for reproducing the problem, but I also provided the source code as well.

ninachen03 commented 1 week ago

This issue has been verified using Visual Studio 17.12.0 Preview 2.0(8.0.91 & 8.0.3) 17.11.4 (7.0.101). Can repro this issue at windows platform.

RuddyOne commented 1 week ago

I have also started seeing this issue with no code change. Do we know what this issue is and any workaround/fixes for now?

ITaluone commented 1 week ago

As I said: I think MAUI is not to blame here. My apps are MAUI.Blazor apps, so every launch of an app launches WebView2 and revealing this issue at app startup immediately.

rswilley commented 5 days ago

I am having this same problem. Last week I didn't have this issue and with no code change I am seeing a flickering popup.

MatthewKing commented 4 days ago

I am having this same issue. No code changes.

stephenquan commented 2 days ago

I was able to reproduce this with the following method:

  1. Create a new .NET MAUI starter app (the one with dotnet_bot.png)
  2. Add <MauiVersion>8.0.91</MauiVersion> underneath <UseMaui>true</UseMaui> in the app's csproj
  3. Add the following WebView to the MainPage.xaml
            <WebView
                HeightRequest="600"
                Source="https://github.com/dotnet/maui/issues/24933"
                WidthRequest="600" />

Here are 5 screenshots representing the different states I see the app go thru:

  1. Launch the app

  2. At approximately 2.8 seconds we see a blank MainPage.xaml appear

  3. At approximately 3.1 seconds we see an unexpected empty window popup (full height, half width, left aligned) and it stays visible for approximately 0.1 seconds

  4. At approximately 3.3 seconds the MainPage.xaml goes to gray for approximately 0.1 seconds

  5. At approximately 3.4 seconds the MainPage.xaml goes back to white and takes a further 1.4 seconds to fully populate

stephenquan commented 2 days ago

I tried the workaround from https://github.com/MicrosoftEdge/WebView2Feedback/issues/4834#issuecomment-2381904393 by adding:

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

to my App.xaml.cs before InitializeComponent(); and it appears to obfuscate the empty window popup. This might be a satisfactory workaround that can be put in place until this issue is fixed.

PureWeen commented 1 day ago

Adding this to our .NET8 SR9.2 milestone for tracking purposes.

It looks like this is a runtime issue https://github.com/MicrosoftEdge/WebView2Feedback/issues/4834#issuecomment-2379786141

Redth commented 1 day ago

Thanks for the reports and the repro step details.

This one is unrelated to MAUI and is reproduceable with a plain .NET WinUI3 app. We're waiting on an upstream fix for the issue already mentioned here: https://github.com/MicrosoftEdge/WebView2Feedback/issues/4834