171

Updated for 2020, I've linked my article where I compare the memory footprints of different approaches to hosting HTML WebView in a basic Windows Desktop application:


Internet Explorer-based WPF WebBrowser control suffers from some keyboard and focus issues and memory leak issues. As an alternative solution to these problems, we're considering available options for hosting Chromium instead of WebBrowser control in our WPF/C# project based around HTML editing. Similar questions have been asked here previously. I've read the answers and done my own research, but I hope to obtain some more feedback from people who have actually used any of the following options in production-quality projects:

Awesomium and Awesomium.NET

It looks very appropriate, but I don't like the fact the project is not open-source and the full source is not easily available. Also, it might be an overkill for our project, as off-screen rendering is not something we really depend on.

Chromium Embedded Framework (CEF) and .NET bindings for CEF

This is probably the best option currently available. The project seems to be alive and active, being currently in sync with Chrome v27. CEF3 uses Chrome multi-process architecture. It also looks like Adobe is giving it some endorsement.

Google's Chrome Frame

While the original purpose of it was to be an HTML5 plugin for IE and Firefox, it actually works as standalone ActiveX control too, so I could wrap it for use with WPF. It exposes a sufficient API for interaction with the inner web page (onmessage, addEventListener/removeEventListener, postMessage). I'm aware Google is to discontinue Chrome Frame, but I assume the sources will remain in Chromium repository. It should not be difficult to update it with the latest Chromium code as we go, and we would have full control over this.

WebKit .NET wrapper

Not exactly Chromium-based and doesn't use V8 engine, so it is not really an option.

Is there any other option I might have overlooked?

I would greatly appreciate if someone shared her/his experience with any of the above options for a real-life, production-quality WPF project. Did you have any integration, licensing, or deployment implications?

TylerH
  • 20,799
  • 66
  • 75
  • 101
noseratio
  • 59,932
  • 34
  • 208
  • 486

8 Answers8

132

You've already listed the most notable solutions for embedding Chromium (CEF, Chrome Frame, Awesomium). There aren't any more projects that matter.

There is still the Berkelium project (see Berkelium Sharp and Berkelium Managed), but it emebeds an old version of Chromium.

CEF is your best bet - it's fully open source and frequently updated. It's the only option that allows you to embed the latest version of Chromium. Now that Per Lundberg is actively working on porting CEF 3 to CefSharp, this is the best option for the future. There is also Xilium.CefGlue, but this one provides a low level API for CEF, it binds to the C API of CEF. CefSharp on the other hand binds to the C++ API of CEF.

Adobe is not the only major player using CEF, see other notable applications using CEF on the CEF wikipedia page.

Updating Chrome Frame is pointless since the project has been retired.

Magnetron
  • 7,495
  • 1
  • 25
  • 41
Czarek Tomczak
  • 20,079
  • 5
  • 49
  • 56
  • You forgot to also say that half the stuff won't work.. like clearing cookies,cache.. setting proxies etc.. Just use Awesomium and save your save the trouble. –  Sep 06 '13 at 22:05
  • 4
    Hehe, nice answer Czarek, thanks for the credit. :) (hadn't seen this until now) – Per Lundberg Oct 30 '13 at 20:12
  • 4
    Of course, worth pointing out: There might clearly be things "missing" in any open source project. Neither Xilium.CefGlue nor CefSharp are any exceptions to that rule. The nice thing about open source stuff is you can actually spend a (reasonably low) amount of time on looking into a smaller issue, and get your fix included. We see that from time to time with CefSharp and it's pretty neat. – Per Lundberg Oct 30 '13 at 20:28
  • 2
    Correct me if I am wrong but does not CefSharp require DLLs that are over 50MB all told? That results in a giant installation setup. The libcef.dll is listed as a major dependency and it is 38MB – Krafty Jan 05 '15 at 06:23
  • 2
    @Krafty Installation setups allow to pack it using algorithms like 7z and this results in size reduced from 55 MB --> to 17 MB. CefSharp size is not much when compared to Google Chrome, which is 152 MB unpacked and 40 MB setup packed. – Czarek Tomczak Jan 05 '15 at 08:29
  • I tried CEFSharp today and should say, it is broken in so many ways that I didn't even bother to continue. even compiling it produced errors that you wouldn't expect to see such as header file not found etc. managed to compile it after 2 hours of looking for issues and manually downloading stuff, I get runtime errors with vague messages. Also folder size is already 180Mb (libcef.dll is 116Mb) – AaA May 17 '20 at 07:58
  • Link to `Xilium.CefGlue` is dead - *"404 | That link has no power here"*. – Pang Oct 27 '20 at 07:55
  • Hi !!!! But, I have an approach more than easy to do in WPF ! //To open html file (could be any file type) if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Process.Start(new ProcessStartInfo("cmd", $"/c start MyPath/myPage.htm") { CreateNoWindow = true }); } //To Print private void Print_click(object sender, RoutedEventArgs e) { MyWebBrowser.InvokeScript("execScript", new object[] { "window.print();", "JavaScript" }); } – Marinpietri Aug 28 '22 at 16:33
10

We had exactly the same challenge some time ago. We wanted to go with CEF3 open source library which is WPF-based and supports .NET 3.5.

Firstly, the author of CEF himself listed binding for different languages here.

Secondly, we went ahead with open source .NET CEF3 binding which is called Xilium.CefGlue and had a good success with it. In cases where something is not working as you'd expect, author usually very responsive to the issues opened in build-in bitbucket tracker

So far it has served us well. Author updates his library to support latest CEF3 releases and bug fixes on regular bases.

Artem
  • 7,275
  • 15
  • 57
  • 97
  • 2
    This is actually a point (coming from "the other side", being CefSharp in this) - CefSharp is 4.0 only since a few months, because of problems supporting 3.5 with newer VS toolsets. (VS2010+ cannot support older frameworks with C++/CLI, which is a bit sad because it forces us to use .NET 4 or a really old Visual Studio version...) – Per Lundberg Oct 30 '13 at 20:14
7

Here is another one:

http://www.essentialobjects.com/Products/WebBrowser/Default.aspx

This one is also based on the latest Chrome engine but it's much easier to use than CEF. It's a single .NET dll that you can simply reference and use.

Jason
  • 465
  • 5
  • 2
4

I have used Awesomium.NET. Although I don't like the fact that it's not open-source, and also the fact that it uses a pretty old Webkit rendering engine, it is really easy to use. That's about the only endorsement I can give it.

Ming Slogar
  • 2,327
  • 1
  • 19
  • 41
  • 2
    Could you share how large your user base was for that project, just roughly? – noseratio Aug 16 '13 at 21:31
  • I never actually deployed the project, so user base was zero. I was only experimenting with options myself. – Ming Slogar Aug 16 '13 at 21:35
  • 2
    I suffered for months supporting an Awesomium-based C# app; it may rock for C++ games but in C# their browser control is downright buggy. The complicated deployment (you need their weird installer to add stuff into the GAC), the buggy behaviour (sometimes it starts up with a black screen, user must restart app manually), and its slow speed (web pages do NOT display as they load, it kinda hangs until the page is fully/half loaded, and it takes 5-10 secs to initialize on a slowish-machine) – Robin Rodricks Jan 17 '16 at 08:02
  • 5
    I finally went with CefSharp and the results were amazing. <100 ms initialization (ie. instant init) and no "bugs". Stuff just works. As it should. Also CefSharp does NOT need to be added into the GAC so no installer changes needed. Just copy your files and go. Did I mention CEF/CefSharp is better than every Mozilla/WebKit C# library I tested? Oh and for heavens sake don't use IE. It works. Yes, it does, but it is totally feature lacking and it performs very badly (speed). – Robin Rodricks Jan 17 '16 at 08:03
  • 1
    @RobinRodricks Exactly my experience too. I nearly gave up the approach, but then I found CefSharp :-) (And who cares about a couple of MBs more, these days, when printer drivers come on a DVD :-) ?) – Xan-Kun Clark-Davis Jan 25 '18 at 03:46
3

UPDATE 2018 MAY:

Alternatively, you can embed Edge browser, but only targetting windows 10.

Here is the solution.

Rahul
  • 2,431
  • 3
  • 35
  • 77
2

I had same issue with my WPF RSS reader, I originally went with Awesomium (I think version 1.6) Awesomium is great. You get a lot of control for caching (images and HTML content), JavaScript execution, intercepting downloads and so forth. It's also super fast. The process isolation means when browser crashes it does not crash the app.

But it's also heavy, even release build adds about 10-15mb (can't remember exact number) and hence a slight start-up penalty. I then realized, only problem I had with IE browser control was that it would throw the JavaScript errors every now and again. But that was fixed with the following snippet.

I hardly used my app on XP or Vista but on Win 7 and above it never crashed (at least not because I used IE browser control)

IOleServiceProvider sp = browser.Document as IOleServiceProvider;
if (sp != null)
{
    IID_IWebBrowserApp = new Guid("0002DF05-0000-0000-C000-000000000046");
    Guid IID_IWebBrowser2 = new Guid("D30C1661-CDAF-11d0-8A3E-00C04FC9E26E");

    webBrowser;
    sp.QueryService(ref IID_IWebBrowserApp, ref IID_IWebBrowser2, out webBrowser);
    if (webBrowser != null)
    {
        webBrowser.GetType().InvokeMember("Silent", 
                BindingFlags.Instance | BindingFlags.Public | BindingFlags.PutDispProperty, null, webBrowser, new object[] { silent });
    }
}
Czarek Tomczak
  • 20,079
  • 5
  • 49
  • 56
Sameer Vartak
  • 948
  • 11
  • 14
  • Thanks for the answer. So did you eventually turn back to IE from Awesomium? – noseratio Aug 21 '13 at 11:32
  • Yes I did. and I've been happy. I use ClickOnce so the deployable was tiny and no start-up freeze! – Sameer Vartak Aug 21 '13 at 12:40
  • Thanks, I've up-voted your answer. BTW, there's [another way](http://stackoverflow.com/questions/6138199/wpf-webbrowser-control-how-to-supress-script-errors/18289217#18289217) to get the inner `IWebBrowser2` interface. – noseratio Aug 21 '13 at 12:48
2

Microsoft is releasing the "Microsoft Edge WebView2" WPF control that will get us a great, free option for embedding Chromium across Windows 10, Windows 8.1, or Windows 7. It is available via Nuget as the package Microsoft.Web.WebView2.

scottheckel
  • 9,106
  • 1
  • 35
  • 47
  • This is a great option, although it's 2020 and these day I would be looking for a cross-platform solution, e. g. [Chromely](https://github.com/chromelyapps/Chromely). – noseratio May 18 '20 at 03:37
  • 1
    I think it depends if you are looking at adding a little web stuff to a desktop app or a desktop app built like a web app. I think you would only use WebView2 only if it was a little web stuff to a desktop app. – scottheckel May 18 '20 at 18:32
0

If you are considering commercial solutions, you can also take a look at DotNetBrowser.

It has plenty of features that you can use for deep integration (e.g. DOM support, JavaScript execution, calling .NET objects from JavaScript, network and cookies handling, printing web pages from code). It is based on the recent Chromium engine and supports a wide range of .NET implementations, from .NET Framework 4.5 to .NET 6. Both WPF and Windows Forms are supported.

Here is a repository containing examples that demonstrate how it can be used in various scenarios: https://github.com/TeamDev-IP/DotNetBrowser-Examples

It is also available on NuGet: https://www.nuget.org/packages/DotNetBrowser/

Anna Dolbina
  • 1
  • 1
  • 8
  • 9
  • What are the advantages of this versus [WebView2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/) or [CefSharp](https://github.com/cefsharp/CefSharp) which are both free and ever-green? – noseratio Nov 19 '21 at 07:11
  • If compared to WebView2, DotNetBrowser has off-screen rendering, which can be used to overcome WPF airspace issue or the inability to embed a browser in a window that has `AllowsTransparency` configured. In addition, it does not rely on the pre-installed browser or runtime, it brings its own instead. – Anna Dolbina Nov 19 '21 at 07:26
  • CefSharp initializes Chromium inside the .NET process, and this approach affects the memory used and sometimes the stability - if something goes wrong within the native part, the whole .NET process may crash. In DotNetBrowser, the Chromium engine lives in a separate process, and you can initialize and use several instances simultaneously, and if something happens inside one of them, there is a way to catch and handle this in the .NET code. – Anna Dolbina Nov 19 '21 at 07:31
  • DotNetBrowser also provides DOM API, which can be used to perform rather complex actions with the DOM elements on the web page, including not only finding elements, but also modifying attributes, filling in form values, clicking buttons and references, and receiving /raising DOM events directly in the .NET code – Anna Dolbina Nov 19 '21 at 07:37
  • 1
    I think it might be a good idea to move these highlights into the answer itself. – noseratio Nov 19 '21 at 08:32