# CefSharp — Embed Chromium in .NET Applications > A .NET wrapper around the Chromium Embedded Framework (CEF) that lets WPF and WinForms applications host a full-featured web browser with bidirectional C#-to-JavaScript communication. ## Install Save as a script file and run: # CefSharp — Embed Chromium in .NET Applications ## Quick Use ```bash dotnet new wpf -n MyBrowser cd MyBrowser dotnet add package CefSharp.Wpf # Add ChromiumWebBrowser control to MainWindow.xaml dotnet run ``` ## Introduction CefSharp brings the full Chromium rendering engine into .NET desktop applications. Rather than relying on the built-in WebBrowser control (which uses Internet Explorer), CefSharp gives your WPF or WinForms app a modern, standards-compliant browser with V8 JavaScript execution, DevTools, and hardware-accelerated rendering. ## What CefSharp Does - Renders modern HTML5, CSS3, and JavaScript inside WPF and WinForms windows - Enables C# code to call JavaScript functions and vice versa through bound objects - Supports custom scheme handlers for intercepting and serving local content - Provides access to Chromium DevTools for debugging embedded web content - Handles downloads, printing, and PDF rendering through the CEF API ## Architecture Overview CefSharp wraps the Chromium Embedded Framework via a managed C++/CLI layer that bridges native CEF C++ code to .NET assemblies. The browser runs in a multi-process architecture identical to Chrome: a main browser process handles the UI, while renderer and GPU processes are spawned as separate executables. The .NET host communicates with these processes through CefSharp's message routing system. ## Self-Hosting & Configuration - Install via NuGet: CefSharp.Wpf, CefSharp.WinForms, or CefSharp.OffScreen - Initialize CEF once at app startup with CefSettings for cache, locale, and proxy - Configure BrowserSettings per instance for JavaScript, image loading, and font controls - CEF binaries are distributed alongside the app; no separate browser install is required - Supports AnyCPU via the CefSharp.Common package with architecture-specific runtime folders ## Key Features - Full Chromium rendering engine with the same capabilities as Google Chrome - JavaScript-to-.NET interop via RegisterJsObject and EvaluateScriptAsync - OffScreen rendering mode for headless HTML-to-image or HTML-to-PDF conversion - Custom request handling and response filtering for advanced proxy and caching scenarios - Active community with long-term support for major .NET and CEF version pairings ## Comparison with Similar Tools - **WebView2** is Microsoft's newer Chromium wrapper but requires Edge to be installed on the target machine - **Electron** bundles Node.js for cross-platform apps; CefSharp is .NET-native for Windows desktop - **Chromely** is a lighter .NET CEF wrapper focused on HTML-as-UI without full browser embedding - **GeckoFX** embeds Firefox's Gecko engine but has a smaller community and less active maintenance - **Wry** is Rust-based and powers Tauri; CefSharp is the go-to choice for C#/.NET codebases ## FAQ **Q: What .NET versions does CefSharp support?** A: CefSharp supports .NET Framework 4.6.2+ and .NET Core/.NET 5+ via separate NuGet packages. **Q: Does CefSharp work on Linux or macOS?** A: CefSharp targets Windows. For cross-platform .NET Chromium embedding, consider alternatives like Chromely or WebView2 on supported platforms. **Q: How large is the CefSharp distribution?** A: The CEF binaries add roughly 200-300 MB to your application. Stripping unused locales and libraries can reduce this. **Q: Can I use CefSharp for automated testing or scraping?** A: Yes. The OffScreen package provides headless browser functionality suitable for rendering, screenshot capture, and automated interaction. ## Sources - https://github.com/cefsharp/CefSharp - https://cefsharp.github.io --- Source: https://tokrepo.com/en/workflows/asset-0c309a10 Author: Script Depot