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

WebView2 crashes after downloading anything #1723

Closed
frank-liu-toronto opened this issue Sep 9, 2021 · 38 comments
Closed

WebView2 crashes after downloading anything #1723

frank-liu-toronto opened this issue Sep 9, 2021 · 38 comments
Labels
bug Something isn't working tracked We are tracking this work internally.

Comments

@frank-liu-toronto
Copy link

frank-liu-toronto commented Sep 9, 2021

Description
WebView2 crashes after downloading anything

Version
SDK: 1.0.961.33
Runtime: Stable Channel, Version 93.0.961.38 (Offcial Build) (64-bit)
Framework: WinForms with .net framework 4.8 (I also tried .net framework 4.6.2)
OS: Windows 10

Repro Steps

  • Create a win form project with VS community, choose .net framework 4.8
  • Install webview2 nuget package (latest stable). Current latest stable version is 1.0.961.33
  • Drag webview2 onto the default form
  • Set Source to http://www.bing.com
  • Run Debug in Visual Studio
  • Search "download 7zip" in the bing page
  • Choose the offical 7-zip.org link in the search result which popups another "browser window."
  • Click on any download link to download a version of 7zip.
  • After the download, close the popup "browser window".
  • Observe the parent default windows form crashes and the following error is reported:

System.InvalidOperationException
HResult=0x80131509
Message=CoreWebView2 members cannot be accessed after the WebView2 control is disposed.
Source=Microsoft.Web.WebView2.Core
StackTrace:
at Microsoft.Web.WebView2.Core.CoreWebView2Controller.MoveFocus(CoreWebView2MoveFocusReason reason)
at Microsoft.Web.WebView2.WinForms.WebView2.OnGotFocus(EventArgs e)
at System.Windows.Forms.Control.InvokeGotFocus(Control toInvoke, EventArgs e)
at System.Windows.Forms.Control.WmSetFocus(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at Microsoft.Web.WebView2.WinForms.WebView2.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Inner Exception 1:
COMException: The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)

Screenshots
image

Additional context

AB#35907166

@frank-liu-toronto frank-liu-toronto added the bug Something isn't working label Sep 9, 2021
@jarno9981
Copy link

jarno9981 commented Sep 9, 2021

@frank-liu-toronto same for my youtube.com just goes black and then crashes

7-zip
Zip
Rar
Exe
Bin
Bat

^^^ for all above it crashes

@jarno9981
Copy link

@champnic major bug when downloading stuff

@champnic
Copy link
Member

champnic commented Sep 9, 2021

Thanks for the bug report! I've added it to our backlog and we'll take a look right away.

@jarno9981 Are you also seeing this on the latest 1.0.961.33 nuget package?
Does it still happen if using a different runtime version (like Canary) or a different SDK package?

@champnic champnic added the tracked We are tracking this work internally. label Sep 9, 2021
@jarno9981
Copy link

jarno9981 commented Sep 9, 2021

@champnic yes the latest release from the nuget

As you metioned 1.0.961.33

I have edge beta and normal edge but no change
At all

.net framework 4.8 winforms

@RichardSteele
Copy link

@champnic Win32 is affected as well: (#1712 (comment)). This bug doesn't appear in Canary channel (95.0.1010.0).

@Deepanghoshs
Copy link

@champnic, Can we have any release date for the fix or can you please give an approximate date for this fix, since we are going for release after this fix on webview2

@champnic
Copy link
Member

The fix is getting checked in today, and will be flowing to the channels shortly afterwards.

@vickiez
Copy link
Contributor

vickiez commented Sep 22, 2021

The fix is now available in Canary 96.0.1023.0. Can you verify that this fixes the issue for you?
Thanks!

@Deepanghoshs
Copy link

@vickiez we are using Microsoft.Web.WebView2 version 1.0.961.33, Can you please confirm, when are we getting the above mentioned updated

@jarno9981
Copy link

@Deepanghoshs latest pre-release 1.0.1018-prerelease

works fine now with edge & edge beta it will not crash anymore for my then

@Deepanghoshs
Copy link

@jarno9981 I have updated to the pre-release 1.0.1018-prerelease in the sample project and our releasing project. But both showing the same error as previously shown. I am afraid the latest fix did not worked for my workflow. I have attached the sample project in Ticket with Sample Project

@Dabraham6
Copy link

Will the fix for this issue just require updating the WebView2 runtime? We are currently using version 93.0.961.52 of the runtime, will it be in the next version whenever that is released?

@Dabraham6
Copy link

Just FYI I tested using the Canary Edge version and our issue is resolved in that

@vickiez
Copy link
Contributor

vickiez commented Sep 23, 2021

Thanks for testing - yes, the fix will come with a Runtime update soon

@Deepanghoshs
Copy link

I am trying to test the sample mentioned by @frank-liu-toronto.

My Environment Details
Windows 10 pro with latest updates Version 10.0.19043 Build 19043
MS Edge WEBview2 Runtime 94.0.992.31
Microsoft Edge Version 96.0.1028.0 (Official build) dev (64-bit)

But still getting the crashing error. Can you provide link to download the patch containing the fix

@champnic
Copy link
Member

champnic commented Oct 4, 2021

@Deepanghoshs You can have your app pickup the Dev runtime using these instructions:
https://docs.microsoft.com/en-us/microsoft-edge/webview2/how-to/set-preview-channel

Thanks!

@champnic champnic closed this as completed Oct 4, 2021
@fvanheeswijk
Copy link

Why is this fix not being actively pushed to the stable channel? In my opinion this is a serious bug and needs to be addressed as soon as possible, we cannot afford to wait until canary propagates to dev, beta and then stable.

@champnic
Copy link
Member

champnic commented Oct 6, 2021

@fvanheeswijk The fix was pushed to stable and should be available in versions 94.0.992.29+ (in the current stable). Are you still seeing this issue in runtimes newer than this?

@fvanheeswijk
Copy link

Yes, it is still crashing the same for us, we are running the 94.0.992.31 stable build.

@jarno9981
Copy link

@fvanheeswijk for me its oke it works not crash anymore

@kolozsaron
Copy link

Sorry, even with Canary 96.0.1043.0, I still get exceptions: after opening 2 new-windows with download, the original window crashes on resize.
I don't know, maybe it's a different problem from the original one... :-/
Please see the source attached and the screen-capture below.

SDK: 1.0.1018-prerelease
Runtime: Canary 96.0.1043.0
OS: Windows 10

ScreenCapture

Exception:

System.InvalidOperationException: CoreWebView2 members cannot be accessed after the WebView2 control is disposed.
Source:	Microsoft.Web.WebView2.Core
Stack trace:
   at Microsoft.Web.WebView2.Core.CoreWebView2Controller.MoveFocus(CoreWebView2MoveFocusReason reason)
   at Microsoft.Web.WebView2.WinForms.WebView2.OnGotFocus(EventArgs e)
   at System.Windows.Forms.Control.InvokeGotFocus(Control toInvoke, EventArgs e)
   at System.Windows.Forms.Control.WmSetFocus(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at Microsoft.Web.WebView2.WinForms.WebView2.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

Inner Exception:
	System.Runtime.InteropServices.COMException: The group or resource is not in the correct state to perform the requested operation. (Exception from HRESULT: 0x8007139F)
	Source:	Microsoft.Web.WebView2.Core
	Stack trace:
	   at Microsoft.Web.WebView2.Core.Raw.ICoreWebView2Controller.MoveFocus(COREWEBVIEW2_MOVE_FOCUS_REASON reason)
	   at Microsoft.Web.WebView2.Core.CoreWebView2Controller.MoveFocus(CoreWebView2MoveFocusReason reason)

WebView2DownloadBugTest.zip

@champnic champnic reopened this Oct 12, 2021
@champnic
Copy link
Member

@kolozsaron and others: I've reopened this issue and the linked bug. We're going to take another look. Thanks for verifying that the issue (or a very similar one) persists and for the repro steps/app!

@fvanheeswijk
Copy link

For us now one download in a WebView2 form works, but in a second form the original issue reproduces again... We'll try to see if we can reproduce it outside our application.

@fvanheeswijk
Copy link

fvanheeswijk commented Oct 19, 2021

So we have finally managed to reproduce the (new) download bug, we have the following source code:

using System;
using System.Threading;
using System.Windows.Forms;

using Microsoft.Web.WebView2.WinForms;

namespace WebView2BugDownload
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(CreateNewForm());
        }

        private static Form CreateNewForm()
        {
            var form = new Form
            {
                Size = new System.Drawing.Size(800, 600)
            };

            var webView2 = new WebView2
            {
                Dock = DockStyle.Fill,
                Source = new Uri(@"https://paste.ee/p/1qgu7")
            };

            webView2.CoreWebView2InitializationCompleted += (sender, e) =>
            {
                webView2.CoreWebView2.ProcessFailed += (sender2, e2) =>
                {
                    MessageBox.Show($"Crashed: {e2.ExitCode} / {e2.ProcessDescription} / {e2.ProcessFailedKind} / {e2.Reason}");
                };
            };

            form.Controls.Add(webView2);

            var button = new Button
            {
                Dock = DockStyle.Bottom,
                Text = "Open new form"
            };
            button.Click += (sender, e) =>
            {
                var thread = new Thread(() =>
                {
                    var newForm = CreateNewForm();
                    newForm.Shown += (sender2, e2) => newForm.Activate();
                    newForm.ShowDialog();
                });
                thread.SetApartmentState(ApartmentState.STA);
                thread.Start();
            };

            form.Controls.Add(button);

            return form;
        }
    }
}

When you keep repeating the following steps after opening the application it will eventually crash (between two and five repetitions necessary usually):

  1. Click 'Open new form'.
  2. Press the 'Download' icon on the paste.ee website.
  3. Close the form.

The message box shown is as follows for me:
Crashed: 1 / / BrowserProcessExited / Unexpected

@champnic Could you please take another look at this issue? This is the only big issue remaining that is preventing our application from going into production.

I tested this for 1.0.961.33 through 1.0.1018-prerelease and it reproduces on all versions, the runtime I'm using is 94.0.992.50.

@champnic
Copy link
Member

@fvanheeswijk We are currently looking into this. Thanks for the repro steps! @vickiez FYI

@champnic
Copy link
Member

We recently put in another fix in runtimes 97.0.1060.0+. Would you be able to test the latest Canary build and see if you are still seeing the issue?

@gabrielrvd
Copy link

gabrielrvd commented Oct 29, 2021

Hi, I had same problem with WPF and 97.0.1060.0 fix it. Thank you!!! When this version rollout in production?

@champnic
Copy link
Member

By default this will be in the 97 release, sometime around the beginning of January. I realize this is a long time, so we'll see about getting it backported to 96 and shipped in mid-November. Thanks!

@fvanheeswijk
Copy link

fvanheeswijk commented Nov 1, 2021

@champnic Unfortunately this issue is still not fixed for us, it still reproduces with the test project listed on #1723 (comment).

I tested it with the latest Microsoft.WebView2 version 1.0.1056-prerelease together with Canary build 97.0.1060.0.
Now it gives the following output when it crashes:
Crashed: -1073741819 / / BrowserProcessExited / Unexpected

@vickiez
Copy link
Contributor

vickiez commented Nov 9, 2021

Hi @fvanheeswijk , do you have a crash dump you can share? We have not been able to repro with the test project you provided.

@fvanheeswijk
Copy link

@vickiez Thank you for checking again, it should still reproduce. However I think I have found the issue! It only seems to reproduce when you do not close the Downloads popup in the right top before closing the form.

@r-cass
Copy link

r-cass commented Nov 10, 2021

Maybe i'm wrong but it seems to be related to "view" management as @fvanheeswijk wrote for this download popup. I've reported the same issue elsewhere (i did not notice this one) #1777 . In this reported issue, the developer encounters issue by using devtools, the stack trace seems to be the same. @vickiez I provided a crash dump #1777 (comment) .

@vickiez
Copy link
Contributor

vickiez commented Nov 10, 2021

@fvanheeswijk @r-cass thanks for the info! Just to double check, do you get the same dump as the one in #1777 with the latest Canary? We made a change to how the popup is closed that resolved this kind of crash for others

@fvanheeswijk
Copy link

@vickiez It still reproduces for us with NuGet package 1.0.1056-prerelease and user agent Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4691.0 Safari/537.36 Edg/97.0.1071.0 (so we should be in the prerelease mode).

However we didn't realize that crashdumps are being written automatically, this is the crashdump we got: ec89732c-e4c9-44cb-a442-d8b1a0468cce.zip

It looks like an access violation has occurred within the browser process.

@r-cass
Copy link

r-cass commented Nov 16, 2021

@vickiez sorry I found this opened issue a bit late, so the crash dump I provided on #1777 is a bit outdated.
However, I tried with with runtime 98.0.1077.0, the issue seems to be fixed, thanks!

@kolozsaron
Copy link

SDK: 1.0.1056-prerelease
Runtime: Canary 98.0.1081.0
...seems to work for me as well. Thanks!

@champnic
Copy link
Member

Thanks everyone for verifying! I'm going to close this issue as fixed, but if you do run into a downloads related crash again, please include stack, crash dump (if available), and what runtime you are using and we'll take a look. Thanks!

@fvanheeswijk
Copy link

Thank you! With the latest Canary 98.0.1084.0 it seems to be fixed indeed (haven't tested other 98.0.x builds).

Can this fix be applied on the current stable release as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tracked We are tracking this work internally.
Projects
None yet
Development

No branches or pull requests