Convert Figma logo to code with AI

cefsharp logoCefSharp

.NET (WPF and Windows Forms) bindings for the Chromium Embedded Framework

9,854
2,922
9,854
55

Top Related Projects

3,220

Chromium Embedded Framework (CEF). A simple framework for embedding Chromium-based browsers in other applications.

113,668

:electron: Build cross-platform desktop apps with JavaScript, HTML, and CSS

12,580

Tiny cross-platform webview library for C/C++. Uses WebKit (GTK/Cocoa) and Edge WebView2 (Windows).

83,441

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.

88,205

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

  1. 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";
    }
}
  1. Executing JavaScript in the browser:
await Browser.EvaluateScriptAsync("document.body.style.backgroundColor = 'red';");
  1. Handling browser events:
Browser.FrameLoadEnd += (sender, args) =>
{
    if (args.Frame.IsMain)
    {
        Console.WriteLine("Page loaded: " + args.Frame.Url);
    }
};

Getting Started

  1. Install CefSharp via NuGet Package Manager:

    Install-Package CefSharp.Wpf
    
  2. 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);
        }
    }
    
  3. 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

3,220

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.

113,668

: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.

12,580

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.

83,441

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.

88,205

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 Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

CefSharp Logo

Build status CefSharp.WinForms CefSharp.Wpf CefSharp.Wpf.HwndHost CefSharp.OffScreen

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.

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.

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!

  • MyGet Pre Release
  • MyGet Pre Release
  • MyGet Pre Release

Pre-release

  • CefSharp.WinForms

  • CefSharp.Wpf

  • CefSharp.OffScreen

  • CefSharp.WinForms.NETCore

  • CefSharp.Wpf.NETCore

  • CefSharp.OffScreen.NETCore

Stable

  • CefSharp.WinForms

  • CefSharp.Wpf

  • CefSharp.OffScreen

  • CefSharp.WinForms.NETCore

  • CefSharp.Wpf.NETCore

  • CefSharp.OffScreen.NETCore

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.

BranchCEF VersionVC++ Version.Net VersionStatus
master65332019*4.6.2**Development
cefsharp/12765332019*4.6.2**Release
cefsharp/12664782019*4.6.2**Unsupported
cefsharp/12564222019*4.6.2**Unsupported
cefsharp/12463672019*4.6.2**Unsupported
cefsharp/12363122019*4.6.2**Unsupported
cefsharp/12262612019*4.6.2**Unsupported
cefsharp/12161672019*4.6.2**Unsupported
cefsharp/12060992019*4.6.2**Unsupported
cefsharp/11960452019*4.6.2**Unsupported
cefsharp/11859932019*4.6.2**Unsupported
cefsharp/11759382019*4.6.2**Unsupported
cefsharp/11658452019*4.6.2**Unsupported
cefsharp/11557902019*4.6.2**Unsupported
cefsharp/11457352019*4.5.2**Unsupported
cefsharp/11356152019*4.5.2**Unsupported
cefsharp/11256152019*4.5.2**Unsupported
cefsharp/11155632019*4.5.2**Unsupported
cefsharp/11054812019*4.5.2**Unsupported
cefsharp/10954142019*4.5.2**Unsupported
cefsharp/10853592019*4.5.2**Unsupported
cefsharp/10753042019*4.5.2**Unsupported
cefsharp/10652492019*4.5.2**Unsupported
cefsharp/10551952019*4.5.2**Unsupported
cefsharp/10451122019*4.5.2**Unsupported
cefsharp/10350602019*4.5.2**Unsupported
cefsharp/10250052019*4.5.2**Unsupported
cefsharp/10149512019*4.5.2**Unsupported
cefsharp/10048962019*4.5.2**Unsupported
cefsharp/9948442019*4.5.2**Unsupported
cefsharp/9847582019*4.5.2**Unsupported
cefsharp/9746922019*4.5.2**Unsupported
cefsharp/9646642019*4.5.2**Unsupported
cefsharp/9546382019*4.5.2**Unsupported
cefsharp/9446062019*4.5.2**Unsupported
cefsharp/9345772019*4.5.2**Unsupported
cefsharp/9245152015*4.5.2**Unsupported
cefsharp/9144722015*4.5.2**Unsupported
cefsharp/9044302015*4.5.2**Unsupported
cefsharp/8943892015*4.5.2**Unsupported
cefsharp/8843242015*4.5.2**Unsupported
cefsharp/8742802015*4.5.2**Unsupported
cefsharp/86424020154.5.2Unsupported
cefsharp/85418320154.5.2Unsupported
cefsharp/84414720154.5.2Unsupported
cefsharp/83410320154.5.2Unsupported
cefsharp/81404420154.5.2Unsupported
cefsharp/79394520154.5.2Unsupported
cefsharp/77386520154.5.2Unsupported
cefsharp/75377020154.5.2Unsupported
cefsharp/73368320154.5.2Unsupported
cefsharp/71357820154.5.2Unsupported
cefsharp/69349720154.5.2Unsupported
cefsharp/67339620154.5.2Unsupported
cefsharp/65332520154.5.2Unsupported
cefsharp/63323920134.5.2Unsupported
cefsharp/62320220134.5.2Unsupported
cefsharp/57298720134.5.2Unsupported
cefsharp/55288320134.5.2Unsupported
cefsharp/53278520134.5.2Unsupported
cefsharp/51270420134.5.2Unsupported
cefsharp/49262320134.0Unsupported
cefsharp/47252620134.0Unsupported
cefsharp/45245420134.0Unsupported
cefsharp/43235720124.0Unsupported
cefsharp/41227220124.0Unsupported
cefsharp/39217120124.0Unsupported
cefsharp/37206220124.0Unsupported

* 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

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.