Skip to content
Attila Szabo edited this page Dec 22, 2023 · 26 revisions

Available Embedded Browsers

  • Cef - Chromium Embedded Framework (Aardvark Platforms Default)
  • Gecko - Browser Engine used in Firefox
    • GeckoFX - Gecko 45, C# Lib, Nuget package available
    • XulFx - Gecko 52, C# Lib, no Nuget package available

not tested

  • Servo - Browser Engine, base for new Gecko used in FF-57-Quantum
  • WebKit - Browser Engine used in Apples Safari
  • KHTML - Browser Engine used in KDEs Konqueror (Ancestor of WebKit, Chromium, Opera,...)
  • EdgeHTML/WebView - UWP Edge Browser Control, Win10 only, not tested with Aardvark Platform

not working

  • WebBrowser - Winforms Internet Explorer Control, doesn't work with Aardvark Platform

Cef Howtos

Aardvark.Media

Features: Development Console, render browser output to texture
Example in aardvark-platform/template MediaUI.fs

Init at the start of your program:

Xilium.CefGlue.ChromiumUtilities.UnpackCef()
Aardvark.UI.Chromium.init args

Winforms-Control:

use ctrl = new Aardvark.UI.AardvarkCefBrowser()
ctrl.StartUrl <- "http://orf.at/"
ctrl.Dock <- DockStyle.Fill

w/o Aardvark.Media

Example code see CefGlueDemo/DemoApp.cs at XiliumCefGlue
or Aardvark.Cef.WinForms/ChromiumStuff.fs from aardvark.media

NuGet Packages:
Another.Unofficial.Xilium.CefGlue.UnpackNativeDependencies
Another.Unofficial.Xilium.CefGlue.WindowsForms

Init at the start of your program:

using Xilium.CefGlue;
class MyCeffApp : CefApp {}
...
ChromiumUtilities.UnpackCef()
CefRuntime.Load();
var settings = new CefSettings();
settings.MultiThreadedMessageLoop = (CefRuntime.Platform == CefRuntimePlatform.Windows);
            
var mainArgs = new CefMainArgs(args);
var app = new MyCeffApp();

var code = CefRuntime.ExecuteProcess(new CefMainArgs(args), app, IntPtr.Zero);
if (code == -1)
    CefRuntime.Initialize(mainArgs, settings, app, IntPtr.Zero);

Setup Winform Control:

class MyCefBrowser : CefWebBrowser {}
...
var ctrl = new MyCefBrowser();
ctrl.Dock = DockStyle.Fill;
ctrl.StartUrl = "http://orf.at";

Separate Executable

By setting CefSettings.BrowserSubprocessPath to an executable with the required Cef code, this exec will be started instead of the main program.
Cef-program:

class Program
{
    private class MyCeffApp : CefApp { }

    static int Main(string[] args)
    {
        return CefRuntime.ExecuteProcess(
            new CefMainArgs(args),
            new MyCeffApp(),
            IntPtr.Zero);
    }
}

Main program:

ChromiumUtilities.UnpackCef();
CefRuntime.Load();
var settings = new CefSettings();
settings.MultiThreadedMessageLoop = (CefRuntime.Platform == CefRuntimePlatform.Windows);
settings.BrowserSubprocessPath = "Dibit-Cef.exe";

CefRuntime.Initialize(
    new CefMainArgs(new string[0]),
    settings,
    new MyCeffApp(),
    IntPtr.Zero);

Oppress CrashPad

Even if a separate executable is registered, Cef still starts the main executable again to create a CrashPad process. This can be detected through the program arguments at the beginning of the programs main method and easily oppressed:

if (args.Any(s => s == "--type=crashpad-handler"))
  Environment.Exit(-1);

This seems to create an error that is written in the file debug.log, but doesn't seem to affect the execution of the main program.

Reinitialize after Shutdown

This is not possible with Cef. After first initialization there will always be one Cef process running in background.
But disposing CefWebBrowser controls will remove their rendering process. Don't forget to decouple from parent, otherwise the whole form might get a shutdown message (or is it just me?).

Gecko Howto

NuGet packages:
32bit: Geckofx45
64bit: Geckofx45.64

Gecko.Xpcom.Initialize("Firefox");
var browser = new Gecko.GeckoWebBrowser() {
    Dock = DockStyle.Fill,
    Navigate("http://orf.at")
}

Fixes

Fix for use with DockPanel Suite by WeiFenLuo

DPS destroys and recreates its Forms. As a result Chromium crashes and Gecko refuses to show anything.
Fix: Detach and reattach browser control

class MyForm : WeifenLuo.WinFormsUI.Docking.DockContent
...
myForm.DockStateChanged += new EventHandler(DockedBrowser_DockStateChanged);
myForm.HandleDestroyed += new EventHandler(DockedBrowser_HandleDestroyed);
...
void DockedBrowser_HandleDestroyed(object sender, EventArgs e) {
    m_myBrowserCtrl.Parent = null;
}

void DockedBrowser_DockStateChanged(object sender, EventArgs e) {
    if (IsHandleCreated) {
        m_myBrowserCtrl.Parent = FindForm()
        m_myBrowserCtrl.BringToFront();
    }
}

Fix for Cef colliding with VS hosting process

CefRuntime starts the current executable several times to initiate its child processes. The VS hosting process breaks this.
There are two solutions to fix this:

  • Disable "Visual Studio hosting process" in the projects properties under Debug
  • Use a different executable to start the child process and oppress CrashPad
Clone this wiki locally