MicrosoftEdge / WebView2Feedback

Feedback and discussions about Microsoft Edge WebView2
https://aka.ms/webview2
447 stars 53 forks source link

App with both WebView2 and CefSharp crashes when opening CefSharp #719

Closed njannink closed 1 year ago

njannink commented 3 years ago

Description My situation: we build plugins for an existing application and because this app is shipped with a very old version of CefSharp we are not able to use modern web technologies in the CefSharp browser. To work around this issue we use WebView2 in the plugins we create to display for example a Blazor website. The issue that now arises is that the main app crashes when a view or form with CefSharp is opened. So it looks like that there are some unmanaged dll issues or something.

When attaching the debugger I'm not able to catch any exception. Even with catch all exceptions enabled.

Anybody has any idea what I possibly could do? And or is there some way to isolate the WebView2 in for example a seperate AppDomain?

Version SDK: 1.0.664.37 Runtime: 87.0.664.55 (64-bit) Framework: WPF OS: Win10

njannink commented 3 years ago

Maybe it has to do something with a listener port? Is there a way to configurate the port being used to listen to the WebView2 messages?

cgeier commented 3 years ago

@njannink Ensure that you are disposing the WebView2 control by calling "Dispose()". The issue may be that you are closing the form containing a WebView2 control without calling Dispose(). If you use ShowDialog to open your form containing your WebView2 control, you need to call Dispose() (perhaps in Form_Closing ) or your application will throw an exception.

ShowDialog (Shows the form as a modal dialog box) - no other action can be performed until the form (window) is closed

Because a form displayed as a dialog box is hidden instead of closed, you must call the Dispose method of the form when the form is no longer needed by your application.

Show (Display a non-modal form)

njannink commented 3 years ago

The control is displayed in a dockable pane. So its actually not closed or displayed as model form

champnic commented 3 years ago

If you try not initializing the WebView2 control (keep the rest of your current code the same), does CefSharp still fail?

njannink commented 3 years ago

Then my WebView2 control gives an exception, because it tries to write the WebView cache to the Program Files folder where the app is installed. I use this init code to make sure the correct path is set:

           var environment = await CoreWebView2Environment.CreateAsync(userDataFolder: CacheFolder);
           await WebView.EnsureCoreWebView2Async(environment);
champnic commented 3 years ago

Makes sense - are you setting the Source property? (That also causes initialization, which could be causing the error you see)

I'm only asking for these tests to try and isolate whether it's something colliding with CefSharp and WebView2, or if perhaps something else got changed when you added WebView2 to your project that could have disrupted your CefSharp usage.

njannink commented 3 years ago

I'm not setting the source property before the WebView is initialized EnsureCoreWebView2Async(env).

When I don't open the pane with the WebView2 control I can still open forms and panes with CefSharp controls on them. But after I opened the pane with the WebView2 control then opening any new view/pane with a CefSharp control causes a crash of the main app.

njannink commented 3 years ago

I got lucky.

We just got a new release of the main app and that release has an updated version of CefSharp. With that version the crash is gone.

Crashing CefSharp version: 65.0.0.0 Ok CefSharp version: 83.4.20.0

So for sure one of the old CefSharp chromium assemblies was clashing with the WebView2 runtime, which is I beleave also chromium.

For me this issue can be closed, but maybe the WebView2 team wants to investigate this further?

hunkydoryrepair commented 3 years ago

I'm interested in this. We link to both CEFSharp and WebView2, although we should only ever run or the other. But if there are some shared libraries and WebView2 updates automatically we could develop a conflict at a later time. Updating cef may only have postponed the problem

njannink commented 3 years ago

That is true. Might be good to figure out how to isolate WebView2 completely from potential other dll's. Might be even a security risk I don't know

rajankapadia commented 3 years ago

Microsoft team, We have same issue in our APP. we have Custom WPF control derived from cef v57 and newly added Win32 native control utilized in our APP. we are seeing crash while we are invoking WPF based cef control .

Any specific suggestion?

gabrieldausque commented 3 years ago

Hello, I've encoutered same issues in a mashup application with the Dataviz app Spotfire from Tibco : When trying to display webview2 in the Spotfire context (which use xilium cefglue, it crashes all new instance of document in it). Didn't find any workaround on it for now, except keep on the old WebBrowser control ....

rajankapadia commented 3 years ago

Hello Gabriel, We have resolved this issue by upgrading CEF v.84.4.10 . That has solved our issue.

Thanks, Rajan

gabrieldausque commented 3 years ago

In my case this is not possible as the application is a third party one, and upgrading cef on which it works is not possible

ksobon commented 3 years ago

Same issue here.

champnic commented 1 year ago

Closing old issues. Let me know if this is still an issue and I can re-open.

Hoya-Lee commented 1 year ago

Closing old issues. Let me know if this is still an issue and I can re-open.

This issue still occurs. After using WebView2 to open a web browser successfully, attempting to open a web browser with CEF results in an internal crash in libcef.dll. This problem occurs 100% of the time in older versions of CEF, regardless of the version of WebView2.

When a crash occurs, the cef3.log file logs the following message: "FATAL: hwnd_util.cc(65): Invalid window handle (0x578)."

rajankapadia commented 1 year ago

Hi @Hoya-Lee , Can we document the steps to re-produce with Version of CEF and webview2 used in application?

we need had solved this issue earlier by aligning the suggested version of CEF and webview2 by Microsoft. Note : we had also seen some occurrences of "internal crash in libcef.dll" in our application. We are curious to learn this more.

-Rajan