-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Quick Start
To get started with CefSharp
checkout the CefSharp.MinimalExample project here on GitHub
. The project contains basic working examples of the WinForms, WPF and OffScreen versions.
- The General Usage Guide has details on many of the features currently available. If you're curious about how to do something, check here first.
- Need to Know/Limitations has a list of important information
- Output files description table (Redistribution) - List of files to be included in your app
- Frequently Asked Questions - Common issues such as JS integration, errors, etc
- Trouble Shooting - Common issues such as freezing, graphics/rendering issues, etc
-
Install one of the following via the
Nuget Package Manager
from withinVisual Studio
-
Review the Post Installation steps in the
Readme.txt
file that's opened inVisual Studio
upon installation. -
Review the Release Notes for the version you just installed, a list of
Known Issues
for the problems we're currently aware of. -
Check out the API Doc, it's version specific, make sure you pick the correct version.
-
When targeting
AnyCPU
withPrefer32bit = true
then no further action is required. Your application is32bit
and will include the32bit
binaries/resources. -
When targeting
AnyCPU
please see https://github.com/cefsharp/CefSharp/issues/1714. TheMinimalExample
demosAnyCPU
support and can be used as a reference. -
For architecture specific builds then set your PlatformTarget to
x86
orx64
.
I strongly suggest setting a RuntimeIdentifier. I've done my best to make the packages work when no RuntimeIdentifier
is specified, there are use cases when you will need to specify a <RuntimeIdentifier/>
for the packages to work correctly.
Specify a RuntimeIdentifier. Use one of the following in your proj file.
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x64</RuntimeIdentifier>
<!-- Will default to your current machine architecture, in most cases this will be win-x64 -->
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>
<!--
You should also set
SelfContained = false (otherwise the whole .Net Framework will be included in your bin folder
-->
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
Without a RuntimeIdentifier
the required files will hopefully be copied to the output folder, as I said there are likely cases where it won't work.
If your proj file specifies multiple platforms e.g. <Platforms>x86;x64</Platforms>
then I'd suggest using the following:
<PropertyGroup Condition="'$(PlatformTarget)' == 'x86'">
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x86</RuntimeIdentifier>
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
</PropertyGroup>
<PropertyGroup Condition="'$(PlatformTarget)' == 'x64'">
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x64</RuntimeIdentifier>
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
</PropertyGroup>
<PropertyGroup Condition="'$(PlatformTarget)' == 'arm64'">
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-arm64</RuntimeIdentifier>
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
</PropertyGroup>
You will need to self host the BrowserSubProcess
using your main application executable.
See https://github.com/cefsharp/CefSharp/issues/3407 for details
- Review the Post Installation steps in the
Readme.txt
file that's opened inVisual Studio
upon installation. - Review the Release Notes for the version you just installed, a list of
Known Issues
for the problems we're currently aware of. - Check out the API Doc, it's version specific, make sure you pick the correct version.
- Add a new instance of the browser
- For WPF use CefSharp.Wpf.ChromiumWebBrowser
<!-- Add a xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" attribute to your parent control --> <!-- Create a new instance in code or in `xaml` --> <Border Grid.Row="1" BorderBrush="Gray" BorderThickness="0,1"> <wpf:ChromiumWebBrowser x:Name="Browser" Address="www.google.com"/> </Border>
- For WinForms use CefSharp.WinForms.ChromiumWebBrowser
using CefSharp.WinForms; //Create a new instance in code or add via the designer var browser = new ChromiumWebBrowser("www.google.com"); parent.Controls.Add(browser); //Load a different url browser.LoadUrl("https://github.com");
- For OffScreen use CefSharp.OffScreen.ChromiumWebBrowser
using CefSharp.OffScreen; //Create a new instance in code var browser = new ChromiumWebBrowser("www.google.com"); //Load a different url browser.LoadUrl("https://github.com");
- For WPF use CefSharp.Wpf.ChromiumWebBrowser
TODO: Improve formatting, anyone with a GitHub
account can help improve this wiki. Please help out!
The following articles are unfortunately outdated, if you have written a new up to date article please include a link to it here.
-
How to use CefSharp in a Winforms application - Note that
AnyCPU
is now supported see https://github.com/cefsharp/CefSharp/issues/1714 - Embedded UI Guide
- If You Like It, Put a HTML5 UI on It
- Quick Start Guide (This guide is outdated, if someone has a newer one please add a link).