Replacing .NET WebBrowser control with a better browser, like Chrome?

Is there any relatively easy way to insert a modern browser into a .NET application?

As far as I understand, the WebBrowser control is a wrapper for IE , which wouldn't be a problem except that it looks like it is a very old version of IE , with all that entails in terms of CSS screw-ups, potential security risks (if the rendering engine wasn't patched, can I really expect the zillion buffer overflow problems to be fixed?), and other issues.

I am using Visual Studio C# (express edition - does it make any difference here?)

I would like to integrate a good web browser in my applications. In some, I just use it to handle the user registration process, interface with some of my website's features and other things of that order, but I have another application in mind that will require more err... control.

I need:

  • A browser that can integrate inside a window of my application (not a separate window)
  • A good support for CSS, js and other web technologies, on par with any modern browser
  • Basic browser functions like "navigate", "back", "reload"...
  • Liberal access to the page code and output.
  • I was thinking about Chrome, since it comes under the BSD license, but I would be just as happy with a recent version of IE.

    As much as possible, I would like to keep things simple. The best would be if one could patch the existing WebBrowser control, which does already about 70% of what I need, but I don't think that's possible.

    I have found an activeX control for Mozilla (http://www.iol.ie/~locka/mozilla/control.htm) but it looks like it's an old version, so it's not necessarily an improvement.

    I am open to suggestions


    Checkout CefSharp .Net bindings, a project I started a while back that thankfully got picked up by the community and turned into something wonderful.

    The project wraps the Chromium Embedded Framework and has been used in a number of major projects including Rdio's Windows client, Facebook Messenger for Windows and Github for Windows.

    It features browser controls for WPF and Winforms and has tons of features and extension points. Being based on Chromium it's blisteringly fast too.

    Grab it from NuGet: Install-Package CefSharp.Wpf or Install-Package CefSharp.WinForms

    Check out examples and give your thoughts/feedback/pull-requests: https://github.com/cefsharp/CefSharp

    BSD Licensed


    Chrome uses (a fork of) Webkit if you didn't know, which is also used by Safari. Here's a few questions that are of the same vein:

  • Embedding Webkit with C#
  • Embedding Gecko (Firefox engine) with C#
  • The webkit one isn't great as the other answer states, one version no longer works (the google code one) and the Mono one is experimental. It'd be nice if someone made the effort to make a decent .NET wrapper for it but it's not something anyone seems to want to do - which is surprising given it now has support for HTML5 and so many other features that the IE(8) engine lacks.

    Update (2014)

    There's new dual-licensed project that allows you embed Chrome into your .NET applications called Awesomium. It comes with a .NET api but requires quite a few hacks for rendering (the examples draw the browser window to a buffer, paint the buffer as an image and refresh on a timer).

    I think this is the browser used by Origin in Battlefield 3.

    Update (2016)

    There is now DotnetBrowser, a commercial alternative to Awesomium. It's based off Chromium.


    I've been testing alternatives to C# Web browser component for few days now and here is my list:

    1. Using newer IE versions 8,9:

    Web Browser component is IE7 not IE8? How to change this?

    Pros:

  • Not much work required to get it running
  • some HTML5/CSS3 support if IE9, full if IE10
  • Cons:

  • Target machine must have target IE version installed, IE10 is still in preview on Win7
  • This doesn't require much work and you can get some HTML5 and CSS3 support although IE9 lacks some of best CSS3 and HTML5 features. But I'm sure you could get IE10 running same way. The problem would be that target system would have to have IE10 installed, and since is still in preview on Windows 7 I would suggest against it.

    2. OpenWebKitSharp

    OpenWebKitSharp is a .net wrapper for the webkit engine based on the WebKit.NET 0.5 project. WebKit is a layout engine used by Chrome/Safari

    Pros:

  • Actively developed
  • HTML5/CSS3 support
  • Cons:

  • Many features not implemented
  • Doesn't support x64 (App must be built for x86)
  • OpenWebKit is quite nice although many features are not yet implemented, I experienced few issues using it with visual studio which throws null object reference here and then in design mode, there are some js problems. Everyone using it will almost immediately notice js alert does nothing. Events like mouseup,mousedown... etc. doesn't work, js drag and drop is buggy and so on..

    I also had some difficulties installing it since it requires specific version of VC redistributable installed, so after exception I looked at event log, found version of VC and installed it.

    3. GeckoFX

    Pros:

  • Works on mono
  • Actively developed
  • HTML5/CSS3 support
  • Cons:

  • D̶o̶e̶s̶n̶'̶t̶ ̶s̶u̶p̶p̶o̶r̶t̶ ̶x̶6̶4̶ ̶(̶A̶p̶p̶ ̶m̶u̶s̶t̶ ̶b̶e̶ ̶b̶u̶i̶l̶t̶ ̶f̶o̶r̶ ̶x̶8̶6̶)̶ - see comments below
  • GeckoFX is a cross platform Webrowser control for embedding into WinForms Applications. This can be used with .NET on Windows and with mono on Linux. Gecko is a layout engine used by Firefox.

    I bumped into few information that GeckoFX is not actively developed which is not true, of course it's always one or two versions behind of Firefox but that is normal, I was really impressed by activity and the control itself. It does everything I needed, but I needed some time to get it running, here's a little tutorial to get it running:

  • Download GeckoFx-Windows-16.0-0.2, here you can check if newer is available GeckoFX
  • Add references to two downloaded dll's
  • Since GeckoFX is wrapper you need XulRunner, go to Version List to see which one you need
  • Now that we know which version of XulRunner we need, we go to Mozilla XulRunner releases, go to version folder -> runtimes -> xulrunner-(your_version).en-US.win32.zip, in our case xulrunner-16.0.en-US.win32.zip
  • Unzip everything and copy all files to your binDebug (or release if your project is set to release)
  • Go to visual studio designer of your form, go to toolbox, right click inside -> Choose items -> Browse -> Find downloaded GeckoFX winforms dll file -> OK
  • Now you should have new control GeckoWebBrowser
  • If your really must use Chrome, take a look at this product called Awesomium, it's free for non-commercial projects, but license is few thousand dollars for commercial.

    链接地址: http://www.djcxy.com/p/21414.html

    上一篇: 如何在ASP.NET MVC中获取我的webapp的基本URL?

    下一篇: 用更好的浏览器替代.NET WebBrowser控件,如Chrome?