CommunityToolkit / Microsoft.Toolkit.Win32

ARCHIVE - This repository contained XAML Islands wrapper controls and tooling for XAML Islands with WinUI 2, see readme for more info about XAML Islands with WinUI 3 and the WindowsAppSDK.
https://aka.ms/windowsappsdk
Other
383 stars 89 forks source link

WPF WebView crashes when "explorer.exe" is not running #165

Open verelpode opened 5 years ago

verelpode commented 5 years ago

I'm submitting a...

Bug report (I searched for similar issues and did not find one)

Current behavior

When you create an instance of WebView inside a WPF app, it crashes when Windows Explorer ("explorer.exe") is not running. (I mean "explorer.exe", not to be confused with "iexplore.exe".)

Expected behavior

Related issues

See also issues #75 and #143. The real underlying cause of those bug reports might actually be this bug I'm reporting now, where WebView crashes when "explorer.exe" is not running.

75 mentions Click-Once but that detail is probably irrelevant because I experience the problem without using Click-Once. #75 mentions Shell Launcher but I don't think it matters whether you use/install Shell Launcher, rather the real issue is that Shell Launcher means "explorer.exe" is not running.

143 mentions Virtual Desktop and this might mean that "explorer.exe" is not running.

Environment

Nuget Package(s): Microsoft.Toolkit.Wpf.UI.Controls.WebView Package Version(s): 6.0.0-preview7.1 Windows 10 Version: 1903 (Build 18362.267) App min and target version: 1903 Device form factor: Desktop Visual Studio: 2019

verelpode commented 5 years ago

@michael-hawker -- May I assist with the debugging of this problem like how I assisted with #8 ? This problem (re explorer.exe) is a major problem for us -- a top priority. We need to find a solution without delay. I was able to assist with #8 because the source code is available, but in the case of this bug re explorer.exe, am I correct or incorrect in thinking that the applicable part of the source code is unfortunately unavailable?

I guess that the bug is located inside Windows.Web.UI.Interop.WebViewControlProcess, but only the source code of the wrapper Microsoft.Toolkit.Win32.UI.Controls.Interop.WinRT.WebViewControlProcess seems to be available. The plan for WinUI 3 includes making source code available. Will Windows.Web.UI.Interop.WebViewControlProcess be part of that?

Is there anything I can do to assist right now?

If the bugfix cannot be released quickly, I'd much appreciate hearing about any possible workarounds to use in the meantime, even if it's an ugly hack. For example, in order to stop WebView crashing in our enterprise environment, could we do something like launch a process that is named "explorer.exe" but isn't really "explorer.exe"? i.e. could I write a small program that does whatever WebView requires, and name it "explorer.exe"? Would that work? What does WebView or WWAHost.exe actually require from explorer.exe?

verelpode commented 5 years ago

When WebView crashes when explorer.exe is not running, the following event is visible via Event Viewer:

Faulting application name: TestWebView-Wpf.exe, version: 1.0.0.0, time stamp: 0x8ff28518
Faulting module name: EdgeManager.dll, version: 11.0.18362.267, time stamp: 0xcbba9044
Exception code: 0xc0000409
Fault offset: 0x0000000000065c48
Faulting process id: 0x23cc
Faulting application start time: 0x01d5515902cf6cbb
Faulting application path: C:\xxxxxx\TestWebView-Wpf.exe
Faulting module path: C:\Windows\System32\EdgeManager.dll
Report Id: 562a44c0-2aed-4a3f-ab12-982012c19c9f
Faulting package full name: 
Faulting package-relative application ID: 

When I run the WPF app in the Visual Studio debugger and tick all exception types in the Exceptions window, the app is just simply terminated, and the VS debugger ends, and no exception is reported at all.

ProcDump gave me only minimal info:

onecoreuap\inetcore\edgemanager\webview\webviewcontrol\win32webviewhostprocess.cpp(403)\EdgeManager.dll!00007FFE095719A1: (caller: 00007FFDC474E04D) 
ReturnHr(1) tid(3334) 80004005 Unspecified error

I wonder whether "EdgeManager.dll" may be invoking a function in "shell32.dll" that tries to communicate with explorer.exe ?

In order to terminate explorer.exe before running WebView, I use the taskkill command with the force option:

taskkill /IM explorer.exe /F
verelpode commented 5 years ago

For comparison between WPF and UWP versions of WebView, I tested the UWP version of WebView (with WebViewExecutionMode.SeparateProcess) when explorer.exe is not running, and it doesn't crash like WPF WebView. It succeeds, displays correctly, and launches WWAHost.exe correctly. However, when you try to click the "X" to close/exit the UWP app, then it malfunctions: Clicking the "X" does nothing. The app refuses to close. The associated "WWAHost.exe" process also remains running.

I created a UWP WebView instance like this:

var myWebView = new Windows.UI.Xaml.Controls.WebView(WebViewExecutionMode.SeparateProcess);
testGridElement.Children.Add(myWebView);
...
myWebView.Navigate(new Uri("http://www.example.com"));

In the case of the UWP WebView, you can terminate explorer.exe either before or after creating the WebView instance at runtime, and the order makes no difference. Instead of setting up a real environment where explorer.exe does not run, you can simply perform tests by using this command to terminate explorer.exe:

taskkill /IM explorer.exe /F

Next, try to click the "X" to close/exit the UWP app that is using WebView. The app refuses to close.

Thus WPF WebView malfunctions far more severely than UWP WebView when explorer.exe is not running.

Version: I tested with a UWP app with the "Target Version" and "Min version" properties set to Windows 10 version 1903.

michael-hawker commented 5 years ago

Thanks for reporting the issues @verelpode, let me try and point some folks to this thread to get some more insight from the platform teams.

verelpode commented 5 years ago

@michael-hawker -- Much appreciated! Does there exist any way to use WebView in WPF with WebViewExecutionMode.SeparateThread instead of WebViewExecutionMode.SeparateProcess? On one hand, the SeparateProcess mode is impressive and I love it, but on the other hand, the current version of it is unusable in our environment because of these 2 reasons:

  1. Crashes when running in a kiosk mode where explorer.exe is not running.
  2. Our app is unable to download critical PDF's from enterprise websites that require temporary/session cookies (INTERNET_COOKIE_HTTPONLY), because Windows.Web.Http.HttpClient (running in our WPF app) has no access to the temporary/session cookies in the separate WebView process. That kind of cookie is only stored in RAM, not to disk, and many websites use that kind of cookie.

Those 2 problems are so big that they completely stop us from deploying the new version outside of the lab. It's frustrating to be so very close but with a roadblock at the end :-(

znakeeye commented 4 years ago

@michael-hawker -- Much appreciated! Does there exist any way to use WebView in WPF with WebViewExecutionMode.SeparateThread instead of WebViewExecutionMode.SeparateProcess? On one hand, the SeparateProcess mode is impressive and I love it, but on the other hand, the current version of it is unusable in our environment because of these 2 reasons:

  1. Crashes when running in a kiosk mode where explorer.exe is not running.
  2. Our app is unable to download critical PDF's from enterprise websites that require temporary/session cookies (INTERNET_COOKIE_HTTPONLY), because Windows.Web.Http.HttpClient (running in our WPF app) has no access to the temporary/session cookies in the separate WebView process. That kind of cookie is only stored in RAM, not to disk, and many websites use that kind of cookie.

Those 2 problems are so big that they completely stop us from deploying the new version outside of the lab. It's frustrating to be so very close but with a roadblock at the end :-(

I'm facing the exact same issue. Did you solve it somehow?