在 C# 中使用 chrome 作为浏览器?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2141668/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use chrome as browser in C#?
提问by Timo
Is there a way to use Google Chrome (or Safari or Firefox) as the browser in a C# application? C# now uses Internet Explorer, and the website they want to use in this program doesn't support it.
有没有办法在 C# 应用程序中使用 Google Chrome(或 Safari 或 Firefox)作为浏览器?C#现在使用Internet Explorer,他们想在这个程序中使用的网站不支持它。
采纳答案by Reed Copsey
You can use WebKit.NET. This is a C# wrapper for WebKit, which is the rendering engine used by Chrome.
您可以使用WebKit.NET。这是 WebKit 的 C# 包装器,WebKit 是 Chrome 使用的渲染引擎。
回答by Travis Gockel
I don't know of any fullChrome component, but you could use WebKit, which is the rendering engine that Chrome uses. The Mono project made WebKit Sharp, which might work for you.
我不知道任何完整的Chrome 组件,但您可以使用 WebKit,它是 Chrome 使用的渲染引擎。Mono 项目制作了WebKit Sharp,它可能对你有用。
回答by iamwill
Try this: http://code.google.com/p/geckofx/
回答by George
OpenWebKitSharp gives you full control over WebKit Nightly, which is very close to webkit in terms of performance and compatibility. Chrome uses WebKit Chromium engine, while WebKit.NET uses Cairo and OpenWebKitSharp Nightly. Chromium should be the best of these builds, while at 2nd place should come Nightly and that's why I suggest OpenWebKitSharp.
OpenWebKitSharp 使您可以完全控制 WebKit Nightly,它在性能和兼容性方面与 webkit 非常接近。Chrome 使用 WebKit Chromium 引擎,而 WebKit.NET 使用 Cairo 和 OpenWebKitSharp Nightly。Chromium 应该是这些版本中最好的,而第二名应该是 Nightly,这就是我建议 OpenWebKitSharp 的原因。
http://gt-web-software.webs.com/libraries.htmat the OpenWebKitSharp section
http://gt-web-software.webs.com/libraries.htm在 OpenWebKitSharp 部分
回答by Liam Martens
I use Awesomium, I think it is better than GeckoFX/WebKit http://awesomium.com
我使用 Awesomium,我认为它比 GeckoFX/WebKit http://awesomium.com
回答by John Hatton
Update for 2014:
2014 年更新:
I use geckofx, a healthy open source project that (as of this writing) keeps up to date pretty well with the latest Firefox releases.
我使用geckofx,这是一个健康的开源项目(在撰写本文时)与最新的 Firefox 版本保持同步。
To embed Chrome, you might consider another healthy looking open source project, Xilium.cefGlue, based on The Chromium Embedded Framework (CEF).
要嵌入 Chrome,您可能会考虑另一个看起来很健康的开源项目Xilium.cefGlue,它基于Chromium 嵌入式框架 (CEF)。
Both of these support WPF and Winforms, and both projects have support for .net and mono.
这两个都支持 WPF 和 Winforms,并且两个项目都支持 .net 和 mono。
回答by Vladimir
Take a look at the DotNetBrowserlibrary. It provides Chromium-based WPF and WinForms browser controls, which are quite easy to embed into .NET application. It supports all the modern web standards including HTML5, CSS3 and JavaScript. The rendered page looks exactly like in Google Chrome.
查看DotNetBrowser库。它提供了基于 Chromium 的 WPF 和 WinForms 浏览器控件,这些控件非常容易嵌入到 .NET 应用程序中。它支持所有现代 Web 标准,包括 HTML5、CSS3 和 JavaScript。呈现的页面看起来与 Google Chrome 中的完全一样。
The library inherits Chromium's multi-process architecture – each web page is rendered in a separate Chromium process, and the application will continue working even after plugin crash or any other unexpected error occurs on the web page.
该库继承了 Chromium 的多进程架构——每个网页都在单独的 Chromium 进程中呈现,即使在插件崩溃或网页上发生任何其他意外错误后,应用程序仍将继续工作。
Here are some other useful features, provided by DotNetBrowser: it is possible to listen to load events, handle network activity, configure proxy, simulate user actions, work with cookies, access and modify DOM, listen to DOM events, call JavaScript from .NET and vice versa, use web camera and microphone on the web page, set up WebRTC-based communication, and more.
以下是 DotNetBrowser 提供的一些其他有用功能:可以侦听加载事件、处理网络活动、配置代理、模拟用户操作、使用 cookie、访问和修改 DOM、侦听 DOM 事件、从 .NET 调用 JavaScript反之亦然,在网页上使用网络摄像头和麦克风,设置基于 WebRTC 的通信等等。
Check out the API Referencefor more details.
查看API 参考以获取更多详细信息。
The code snippet below demonstrates how to create a BrowserView, embed it into a Form, and load a URL:
下面的代码片段演示了如何创建一个 BrowserView,将它嵌入到一个表单中,并加载一个 URL:
using System.Windows.Forms;
using DotNetBrowser;
using DotNetBrowser.WinForms;
namespace WinForms.DotNetBrowser
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
BrowserView browserView = new WinFormsBrowserView();
Controls.Add((Control) browserView);
browserView.Browser.LoadURL("http://www.youtube.com");
}
}
}
Once you run the example above you will get the following output:
运行上面的示例后,您将获得以下输出:
The library is commercial. Commercial licenses include support packages for different team sizes. It is also possible to purchase the library's source code.
图书馆是商业性的。商业许可证包括针对不同团队规模的支持包。也可以购买库的源代码。
Besides its own page the component is available as NuGet packageand as VSIX packagein the Visual Studio Marketplace.
除了它自己的页面之外,该组件还可以作为NuGet 包和Visual Studio Marketplace 中的VSIX 包使用。
回答by daniel.herken
Update 2016:
2016 年更新:
Unfortunately most of the above solutions are out of date and no longer maintained.
不幸的是,上述大多数解决方案都已过时且不再维护。
There are 3 additional options I can suggest that are still actively developed:
我可以建议另外 3 个选项仍在积极开发中:
A .Net component that can be used to integrate the Chrome engineinto your .Net Application. Based on CefGluebut a little faster on updates to the latest Chrome version. Also there is a commercial supportoption available which might come in handy for some. Of course the component itself is open source.
一个 .Net 组件,可用于将Chrome 引擎集成到您的 .Net 应用程序中。基于CefGlue,但在更新到最新的 Chrome 版本时速度要快一些。还有一个商业支持选项可能对某些人有用。当然,组件本身是开源的。
Another .Net component which can be used to integrate the Firefox engineinto your .Net application. This is based on Geckofxbut unlike the current version of Geckofx this will work with a normal release build of Firefox. To use Geckofx you will need to build Firefox yourself. Again commercial supportis available but the component itself is fully open source.
另一个 .Net 组件可用于将Firefox 引擎集成到您的 .Net 应用程序中。这是基于Geckofx 的,但与当前版本的 Geckofx 不同,这将适用于 Firefox 的正常发布版本。要使用 Geckofx,您需要自己构建 Firefox。再次提供商业支持,但组件本身是完全开源的。
Need all the different browsers in your .Net Application? Which the BrowseEmAll Core API you can integrate Chrome, Firefox, Webkit and Internet Explorerinto your application. This is a commercial productthough so be warned.
在您的 .Net 应用程序中需要所有不同的浏览器?您可以使用 BrowseEmAll Core API将 Chrome、Firefox、Webkit 和 Internet Explorer集成到您的应用程序中。这是一种商业产品,但请注意。
(Full disclosure: I work for this company so take everything I say with a grain of salt)
(完全披露:我在这家公司工作,所以对我所说的一切持保留态度)
回答by Juan
1/3/2017 --> January the 3rd 2017
1/3/2017 --> 2017 年 1 月 3 日
Hi there, today I found this article to achieve this, the article is called "Creating an HTML UI for Desktop .NET Applications" and is intended to embed a chromium based control in a WPF application. It saved me the day.
您好,今天我找到了这篇文章来实现这一点,该文章称为“为桌面 .NET 应用程序创建 HTML UI”,旨在在 WPF 应用程序中嵌入基于铬的控件。它救了我一天。
https://www.infoq.com/articles/html-desktop-net
https://www.infoq.com/articles/html-desktop-net
I hope it helps somebody else.
我希望它可以帮助别人。
NOTE: it is based on DotNetBrowser, see license agreement here: https://www.teamdev.com/dotnetbrowser-licence-agreement
注意:它基于 DotNetBrowser,请参阅此处的许可协议:https://www.teamdev.com/dotnetbrowser-licence-agreement