cefsharp/CefSharp · error · Exception

Browser has already been created. BrowserSettings must be se

Error message

Browser has already been created. BrowserSettings must be set before the underlying CEF browser is created.

What it means

BrowserSettings configures the underlying CEF browser (cache path, webgl, fonts, etc.) and must be applied before the native browser instance is created. Once the browserCreated flag is true, the native browser is live and its settings are immutable; assigning a new BrowserSettings instance at that point throws.

Source

Thrown at CefSharp.Wpf/HwndHost/ChromiumWebBrowser.cs:225

        {
            get
            {
                return Interlocked.CompareExchange(ref disposeSignaled, 1, 1) == 1;
            }
        }

        /// <summary>
        /// Gets or sets the browser settings.
        /// </summary>
        /// <value>The browser settings.</value>
        public IBrowserSettings BrowserSettings
        {
            get { return browserSettings; }
            set
            {
                if (browserCreated)
                {
                    throw new Exception("Browser has already been created. BrowserSettings must be " +
                                        "set before the underlying CEF browser is created.");
                }

                //New instance is created in the constructor, if you use
                //xaml to initialize browser settings then it will also create a new
                //instance, so we dispose of the old one
                if (browserSettings != null && browserSettings.AutoDispose)
                {
                    browserSettings.Dispose();
                }

                browserSettings = value;
            }
        }
        /// <summary>
        /// Gets or sets the request context.
        /// </summary>
        /// <value>The request context.</value>

View on GitHub (pinned to 16bc6e0711)

Solutions

  1. Set BrowserSettings in XAML or in the constructor before the control is added to the visual tree.
  2. If configuring in code, set it immediately after `new ChromiumWebBrowser()` and before adding the control to a parent.
  3. Use CefSettings (global) for settings that must change after browser creation.

Example fix

// before — throws because browser is already created
private void OnLoaded(object s, EventArgs e)
{
    browser.BrowserSettings = new BrowserSettings { WebGl = CefState.Disabled };
}

// after — set before visual tree attachment
var browser = new ChromiumWebBrowser
{
    BrowserSettings = new BrowserSettings { WebGl = CefState.Disabled }
};
// then add browser to the layout
Defensive patterns

Strategy: validation

Validate before calling

if (browser.browserCreated) // if accessible; otherwise check IsBrowserInitialized
{
    // cannot set BrowserSettings now
    return;
}
browser.BrowserSettings = settings;

Try / catch

try
{
    browser.BrowserSettings = settings;
}
catch (Exception ex) when (ex.Message.Contains("Browser has already been created"))
{
    Log.Warn("BrowserSettings cannot be changed after browser creation", ex);
}

Prevention

When it happens

Trigger: Setting the BrowserSettings property after the control has been loaded into the visual tree, after CreateBrowser was called, or after IsBrowserInitialized has become true.

Common situations: Assigning BrowserSettings in a Loaded event handler, a data-binding callback, or any code path that runs after the WPF control has rendered and triggered browser creation.

Related errors


AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13). Data as JSON: /api/errors/fafcc76f3caef16c. Report an issue: GitHub.