Skip to content

Instantly share code, notes, and snippets.

@privatedev11
Created November 27, 2021 12:41
Show Gist options
  • Save privatedev11/12407bf850739b95f25eac060de96e6f to your computer and use it in GitHub Desktop.
Save privatedev11/12407bf850739b95f25eac060de96e6f to your computer and use it in GitHub Desktop.
With CEFSharp, you can easily embed a site using the Chromium Embedded Framework

CEFSharp

CEFSharp is a great nuget package for putting Chromium in your C# program. I will be using WinForms.

1. Get the package

Get the package here: https://www.nuget.org/packages/CefSharp.WinForms/

2. Add the imports

Add the following to the imports section:

using CefSharp;
using CefSharp.WinForms; 

3. Add the code!

Paste this code in:

public ChromiumWebBrowser browser;
 
public void InitBrowser()
{
    Cef.Initialize(new CefSettings());
    browser = new ChromiumWebBrowser("https://duckduckgo.com");
    this.Controls.Add(browser);
    browser.Dock = DockStyle.Fill;
}

Change DuckDuckGo to the site you want to view. You must type the whole URL with https before it or it won't work. The easist way to do this is just right clicking on the address bar in your browser and copying the link.

3. Call InitBrowser()

Call InitBrowser at InitializeConponent

InitBrowser();

4. Run it!

When running, you should see the site!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment