Top Related Projects
Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS
Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows).
Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
JavaScript API for Chrome and Firefox
Quick Overview
CefSharp is a .NET wrapper for the Chromium Embedded Framework (CEF). It allows developers to embed a Chromium-based browser in .NET applications, providing a powerful web engine for rendering HTML, CSS, and JavaScript within Windows Forms, WPF, and other .NET applications.
Pros
- Enables the creation of modern, web-based user interfaces in desktop applications
- Supports multiple .NET frameworks (WinForms, WPF, OffScreen)
- Regular updates and active community support
- High performance and compatibility with modern web standards
Cons
- Large file size due to Chromium dependencies
- Steep learning curve for developers new to CEF
- Memory usage can be high, especially for multiple instances
- Occasional compatibility issues with certain .NET versions or environments
Code Examples
- Initializing CefSharp in a WPF application:
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
CefSettings settings = new CefSettings();
Cef.Initialize(settings);
Browser.Address = "https://www.example.com";
}
}
- Executing JavaScript in the browser:
await Browser.EvaluateScriptAsync("document.body.style.backgroundColor = 'red';");
- Handling browser events:
Browser.FrameLoadEnd += (sender, args) =>
{
if (args.Frame.IsMain)
{
Console.WriteLine("Page loaded: " + args.Frame.Url);
}
};
Getting Started
-
Install CefSharp via NuGet Package Manager:
Install-Package CefSharp.Wpf
-
Add the following code to your application's startup (e.g., App.xaml.cs):
public partial class App : Application { protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); CefSettings settings = new CefSettings(); Cef.Initialize(settings); } }
-
Add a ChromiumWebBrowser control to your XAML:
<Window x:Class="YourNamespace.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:cefSharp="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" Title="MainWindow" Height="450" Width="800"> <Grid> <cefSharp:ChromiumWebBrowser x:Name="Browser" Address="https://www.example.com"/> </Grid> </Window>
Competitor Comparisons
Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
Pros of CEF
- Lower-level API providing more control and flexibility
- Cross-platform support (Windows, macOS, Linux)
- Directly maintained by the Chromium Embedded Framework team
Cons of CEF
- Steeper learning curve due to C/C++ implementation
- Requires more manual setup and configuration
- Less integrated with .NET ecosystem
Code Comparison
CEF (C++):
CefRefPtr<SimpleHandler> handler(new SimpleHandler());
CefBrowserSettings browser_settings;
CefWindowInfo window_info;
window_info.SetAsPopup(NULL, "CEF Example");
CefBrowserHost::CreateBrowser(window_info, handler, "https://www.example.com", browser_settings, NULL);
CefSharp (C#):
var browser = new ChromiumWebBrowser("https://www.example.com");
this.Controls.Add(browser);
Summary
CEF provides a lower-level, cross-platform API with more control, while CefSharp offers a more .NET-friendly approach with easier integration for C# developers. CEF requires more setup but provides greater flexibility, whereas CefSharp simplifies implementation at the cost of some customization options. The choice between the two depends on the specific project requirements, target platforms, and developer expertise.
:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS
Pros of Electron
- Cross-platform development for desktop apps using web technologies
- Large ecosystem with extensive documentation and community support
- Easier integration with Node.js and npm packages
Cons of Electron
- Larger application size due to bundled Chromium and Node.js
- Higher memory usage compared to native applications
- Potential security concerns due to full system access
Code Comparison
Electron (JavaScript):
const { app, BrowserWindow } = require('electron')
function createWindow () {
const win = new BrowserWindow({ width: 800, height: 600 })
win.loadFile('index.html')
}
app.whenReady().then(createWindow)
CefSharp (C#):
public class BrowserForm : Form
{
public ChromiumWebBrowser browser;
public BrowserForm()
{
browser = new ChromiumWebBrowser("https://example.com");
Controls.Add(browser);
}
}
CefSharp focuses on embedding Chromium in .NET applications, while Electron provides a full framework for building cross-platform desktop apps using web technologies. CefSharp offers more granular control over the embedded browser but requires more setup. Electron simplifies the development process but comes with a larger footprint and potential performance overhead.
Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows).
Pros of webview
- Lightweight and minimal dependencies
- Cross-platform support (Windows, macOS, Linux)
- Simple API with fewer lines of code required
Cons of webview
- Limited functionality compared to full-featured browser engines
- Less extensive documentation and community support
- Fewer customization options for advanced use cases
Code Comparison
CefSharp:
public class BrowserForm : Form
{
public ChromiumWebBrowser browser;
public BrowserForm()
{
browser = new ChromiumWebBrowser("https://example.com");
this.Controls.Add(browser);
}
}
webview:
#include <webview.h>
int main() {
webview::webview w(true, nullptr);
w.navigate("https://example.com");
w.run();
return 0;
}
The code comparison demonstrates that webview requires fewer lines of code to create a basic web view, while CefSharp offers more extensive configuration options but with a slightly more complex setup.
CefSharp provides a full-featured Chromium-based browser control, offering advanced features and better compatibility with modern web technologies. It's ideal for applications requiring a complete browser experience.
webview, on the other hand, focuses on simplicity and minimal overhead, making it suitable for lightweight applications that need basic web rendering capabilities without the complexity of a full browser engine.
Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
Pros of Tauri
- Smaller application size due to native OS components
- Better performance and resource efficiency
- Cross-platform support for desktop and mobile
Cons of Tauri
- Steeper learning curve for developers new to Rust
- Smaller ecosystem and community compared to CefSharp
- Limited to web technologies for UI development
Code Comparison
CefSharp (C#):
public class BrowserForm : Form
{
public ChromiumWebBrowser browser;
public BrowserForm()
{
browser = new ChromiumWebBrowser("https://example.com");
Controls.Add(browser);
}
}
Tauri (Rust):
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}!", name)
}
fn main() {
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
Both CefSharp and Tauri allow developers to create desktop applications using web technologies. CefSharp uses Chromium Embedded Framework and is primarily for .NET developers, while Tauri leverages native OS components and Rust for better performance and smaller application size. CefSharp has a larger ecosystem and community, making it easier for .NET developers to adopt, while Tauri offers cross-platform support for both desktop and mobile platforms.
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
Pros of Playwright
- Cross-browser support (Chromium, Firefox, WebKit) out of the box
- Built-in test runner and assertion library
- Powerful auto-wait mechanism for improved test stability
Cons of Playwright
- Limited to Node.js environment
- Steeper learning curve for developers familiar with traditional browser automation tools
Code Comparison
Playwright
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await browser.close();
})();
CefSharp
using CefSharp;
using CefSharp.WinForms;
public partial class Form1 : Form
{
public ChromiumWebBrowser browser;
public Form1()
{
InitializeComponent();
browser = new ChromiumWebBrowser("https://example.com");
this.Controls.Add(browser);
}
}
Summary
Playwright offers a more modern approach to browser automation with cross-browser support and built-in testing features. It's ideal for Node.js developers working on complex web applications. CefSharp, on the other hand, provides deeper integration with .NET applications and is better suited for developers building desktop applications with embedded web content.
JavaScript API for Chrome and Firefox
Pros of Puppeteer
- Cross-platform compatibility (Windows, macOS, Linux)
- Easier to set up and use, especially for web developers familiar with JavaScript
- More extensive API for web automation and testing
Cons of Puppeteer
- Limited to Chromium-based browsers
- Requires Node.js runtime
- May have higher memory usage for certain operations
Code Comparison
CefSharp (C#):
using CefSharp;
using CefSharp.WinForms;
ChromiumWebBrowser browser = new ChromiumWebBrowser("https://example.com");
browser.LoadingStateChanged += OnLoadingStateChanged;
Puppeteer (JavaScript):
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
})();
Both CefSharp and Puppeteer are powerful tools for web automation and testing, but they cater to different ecosystems. CefSharp is ideal for .NET developers looking to embed web content in their applications, while Puppeteer is better suited for web developers who need a flexible, JavaScript-based solution for browser automation and testing.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Got a quick question? Discussions here on GitHub
is the preferred place to ask!
CefSharp lets you embed Chromium in .NET apps. It is a lightweight .NET wrapper around the Chromium Embedded Framework (CEF) by Marshall A. Greenblatt. About 30% of the bindings are written in C++/CLI with the majority of code here is C#. It can be used from C# or VB, or any other CLR language. CefSharp provides both WPF and WinForms web browser control implementations.
CefSharp is BSD licensed, so it can be used in both proprietary and free/open source applications. For the full details, see the LICENSE file.
If you like and use CefSharp please consider signing up for a small monthly donation, even $25 can help tremendously. See Financial Support for more details.
Releases
Stable binaries are released on NuGet, and contain everything you need to embed Chromium in your .Net/CLR application. For usage see the Quick Start guide or checkout CefSharp.MinimalExample project for basic demos using the CefSharp NuGet packages.
- CefSharp.WinForms
- CefSharp.Wpf
- CefSharp.OffScreen
- CefSharp.Wpf.HwndHost (A HwndHost based WPF implementation, similar to hosting the WinForms version in WPF, supports data binding, airspace issues apply).
Documentation
- See the CefSharp.Wpf.Example or CefSharp.WinForms.Example projects for example web browsers built with CefSharp. They demo most of the available features.
- See the CefSharp.MinimalExample project for a basic demo of using the CefSharp NuGet packages.
- See the General Usage Guide in help getting started/dealing with common scenarios.
- See the Wiki for work-in-progress documentation
- See the FAQ for help with common issues
- Upgrading from an earlier version of CefSharp? See the ChangeLog for breaking changes and upgrade tips.
- CefSharp API generated from the source code comments.
Contact
Please keep the Issue Tracker
for Bugs only please! Before submitting a PR
please read CONTRIBUTING.
- CefSharp Discussions is generally where
CefSharp
specific questions should be asked, please search before posting, thanks! - Stackoverflow is where generic html/javascript/C# questions can be asked.
- Chromium Embedded Framework(CEF) Forum
Branches & Forks
This is the official
CefSharp fork, as maintained by the CefSharp community. You can also view the entire network of public forks/branches.
Development is done in the master
branch. New features are preferably added in feature branches, if the changes are more than trivial. New PR's
should be targeted against master
.
When a new release is imminent a release
branch is created. We try to avoid making public facing API
changes in release
branches (Adding new features is fine, just not breaking changes).
Releases
CI Builds
Every commit on master
produces a Nuget
package. Use at your own risk!
Pre-release
Stable
Release Branches
With each release a new branch is created, for example the 92.0.260
release corresponds to the cefsharp/92 branch.
If you're new to CefSharp
and are downloading the source to check it out, please use a Release branch.
* VC++ 2019 is required starting with version 93
** For .Net Core Packages .Net Core 3.1 or .Net 5/6/7 are required.
Branch | CEF Version | VC++ Version | .Net Version | Status |
---|---|---|---|---|
master | 6533 | 2019* | 4.6.2** | Development |
cefsharp/127 | 6533 | 2019* | 4.6.2** | Release |
cefsharp/126 | 6478 | 2019* | 4.6.2** | Unsupported |
cefsharp/125 | 6422 | 2019* | 4.6.2** | Unsupported |
cefsharp/124 | 6367 | 2019* | 4.6.2** | Unsupported |
cefsharp/123 | 6312 | 2019* | 4.6.2** | Unsupported |
cefsharp/122 | 6261 | 2019* | 4.6.2** | Unsupported |
cefsharp/121 | 6167 | 2019* | 4.6.2** | Unsupported |
cefsharp/120 | 6099 | 2019* | 4.6.2** | Unsupported |
cefsharp/119 | 6045 | 2019* | 4.6.2** | Unsupported |
cefsharp/118 | 5993 | 2019* | 4.6.2** | Unsupported |
cefsharp/117 | 5938 | 2019* | 4.6.2** | Unsupported |
cefsharp/116 | 5845 | 2019* | 4.6.2** | Unsupported |
cefsharp/115 | 5790 | 2019* | 4.6.2** | Unsupported |
cefsharp/114 | 5735 | 2019* | 4.5.2** | Unsupported |
cefsharp/113 | 5615 | 2019* | 4.5.2** | Unsupported |
cefsharp/112 | 5615 | 2019* | 4.5.2** | Unsupported |
cefsharp/111 | 5563 | 2019* | 4.5.2** | Unsupported |
cefsharp/110 | 5481 | 2019* | 4.5.2** | Unsupported |
cefsharp/109 | 5414 | 2019* | 4.5.2** | Unsupported |
cefsharp/108 | 5359 | 2019* | 4.5.2** | Unsupported |
cefsharp/107 | 5304 | 2019* | 4.5.2** | Unsupported |
cefsharp/106 | 5249 | 2019* | 4.5.2** | Unsupported |
cefsharp/105 | 5195 | 2019* | 4.5.2** | Unsupported |
cefsharp/104 | 5112 | 2019* | 4.5.2** | Unsupported |
cefsharp/103 | 5060 | 2019* | 4.5.2** | Unsupported |
cefsharp/102 | 5005 | 2019* | 4.5.2** | Unsupported |
cefsharp/101 | 4951 | 2019* | 4.5.2** | Unsupported |
cefsharp/100 | 4896 | 2019* | 4.5.2** | Unsupported |
cefsharp/99 | 4844 | 2019* | 4.5.2** | Unsupported |
cefsharp/98 | 4758 | 2019* | 4.5.2** | Unsupported |
cefsharp/97 | 4692 | 2019* | 4.5.2** | Unsupported |
cefsharp/96 | 4664 | 2019* | 4.5.2** | Unsupported |
cefsharp/95 | 4638 | 2019* | 4.5.2** | Unsupported |
cefsharp/94 | 4606 | 2019* | 4.5.2** | Unsupported |
cefsharp/93 | 4577 | 2019* | 4.5.2** | Unsupported |
cefsharp/92 | 4515 | 2015* | 4.5.2** | Unsupported |
cefsharp/91 | 4472 | 2015* | 4.5.2** | Unsupported |
cefsharp/90 | 4430 | 2015* | 4.5.2** | Unsupported |
cefsharp/89 | 4389 | 2015* | 4.5.2** | Unsupported |
cefsharp/88 | 4324 | 2015* | 4.5.2** | Unsupported |
cefsharp/87 | 4280 | 2015* | 4.5.2** | Unsupported |
cefsharp/86 | 4240 | 2015 | 4.5.2 | Unsupported |
cefsharp/85 | 4183 | 2015 | 4.5.2 | Unsupported |
cefsharp/84 | 4147 | 2015 | 4.5.2 | Unsupported |
cefsharp/83 | 4103 | 2015 | 4.5.2 | Unsupported |
cefsharp/81 | 4044 | 2015 | 4.5.2 | Unsupported |
cefsharp/79 | 3945 | 2015 | 4.5.2 | Unsupported |
cefsharp/77 | 3865 | 2015 | 4.5.2 | Unsupported |
cefsharp/75 | 3770 | 2015 | 4.5.2 | Unsupported |
cefsharp/73 | 3683 | 2015 | 4.5.2 | Unsupported |
cefsharp/71 | 3578 | 2015 | 4.5.2 | Unsupported |
cefsharp/69 | 3497 | 2015 | 4.5.2 | Unsupported |
cefsharp/67 | 3396 | 2015 | 4.5.2 | Unsupported |
cefsharp/65 | 3325 | 2015 | 4.5.2 | Unsupported |
cefsharp/63 | 3239 | 2013 | 4.5.2 | Unsupported |
cefsharp/62 | 3202 | 2013 | 4.5.2 | Unsupported |
cefsharp/57 | 2987 | 2013 | 4.5.2 | Unsupported |
cefsharp/55 | 2883 | 2013 | 4.5.2 | Unsupported |
cefsharp/53 | 2785 | 2013 | 4.5.2 | Unsupported |
cefsharp/51 | 2704 | 2013 | 4.5.2 | Unsupported |
cefsharp/49 | 2623 | 2013 | 4.0 | Unsupported |
cefsharp/47 | 2526 | 2013 | 4.0 | Unsupported |
cefsharp/45 | 2454 | 2013 | 4.0 | Unsupported |
cefsharp/43 | 2357 | 2012 | 4.0 | Unsupported |
cefsharp/41 | 2272 | 2012 | 4.0 | Unsupported |
cefsharp/39 | 2171 | 2012 | 4.0 | Unsupported |
cefsharp/37 | 2062 | 2012 | 4.0 | Unsupported |
* VC++ 2019 is required starting with version 93
** For .Net Core Packages .Net Core 3.1/.Net 5.0 is required.
Financial Support
Is your company making money thanks to CefSharp
? Do you rely on regular updates to the project? Alex Maitland needs your support! Signup to GitHub Sponsors.
One-Time or Recurring contributions can be made through GitHub Sponsors it only takes a GitHub account and a credit card. You can also make a One-Time contribution via PayPal.
As a stay at home dad I (@amaitland) rely on your contributions to help support my family.
Links
- CefGlue: An alternative .NET CEF wrapper built using P/Invoke.
- CEF GitHub Project : The official CEF issue tracker
- CEF Forum : The official CEF Forum
- CEF API Docs : Well worth a read if you are implementing a new feature
- CefSharp API Doc
Projects using CefSharp
- HtmlView : Visual Studio extension bringing CefSharp for showing HTML pages inside VS.
- SharpBrowser : The fastest web browser for C# with tabbed browsing and HTML5/CSS3.
- Chromely CefSharp : Build HTML Desktop Apps on .NET/.NET Core 3/.NET 5 using native GUI, HTML5/CSS.
Top Related Projects
Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.
:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS
Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows).
Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
JavaScript API for Chrome and Firefox
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot