cefsharp/CefSharp · error · Exception

Browser has already been created. RequestContext must be set

Error message

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

What it means

Thrown by the WPF ChromiumWebBrowser.RequestContext setter when browserCreated is true. The RequestContext (cookie/cache partition, proxy, preferences) is bound into CEF at browser creation and is immutable afterward; the WPF control creates the browser lazily on load, so assigning RequestContext after load is rejected.

Source

Thrown at CefSharp.Wpf/ChromiumWebBrowser.cs:229

                {
                    browserSettings.Dispose();
                }

                browserSettings = value;
            }
        }
        /// <summary>
        /// Gets or sets the request context.
        /// </summary>
        /// <value>The request context.</value>
        public IRequestContext RequestContext
        {
            get { return requestContext; }
            set
            {
                if (browserCreated)
                {
                    throw new Exception("Browser has already been created. RequestContext must be " +
                                        "set before the underlying CEF browser is created.");
                }
                if (value != null && !Core.ObjectFactory.RequestContextType.IsAssignableFrom(value.UnWrap().GetType()))
                {
                    throw new Exception(string.Format("RequestContext can only be of type {0} or null", Core.ObjectFactory.RequestContextType));
                }
                requestContext = value;
            }
        }
        /// <summary>
        /// Implement <see cref="IRenderHandler"/> and control how the control is rendered
        /// </summary>
        /// <value>The render Handler.</value>
        public IRenderHandler RenderHandler { get; set; }
        /// <summary>
        /// Implement <see cref="IAccessibilityHandler" /> to handle events related to accessibility.
        /// </summary>
        /// <value>The accessibility handler.</value>

View on GitHub (pinned to 16bc6e0711)

Solutions

  1. Assign RequestContext before the control loads (in the constructor or immediately after instantiation).
  2. For per-session isolation, create a new ChromiumWebBrowser with the desired RequestContext rather than reassigning.
  3. If binding in XAML, make the source available at binding init time.
  4. Avoid showing the window / rendering the control before assigning.

Example fix

// before
Browser.RequestContext = new RequestContext(settings); // throws after load

// after
var rc = new RequestContext(settings);
var browser = new ChromiumWebBrowser { RequestContext = rc };
// then add to visual tree / show
Defensive patterns

Strategy: validation

Validate before calling

if (!browser.IsBrowserInitialized)
{
    browser.RequestContext = new RequestContext(settings);
}

Prevention

When it happens

Trigger: Setting RequestContext after the WPF control has loaded/rendered; data-binding it to a value that resolves post-load; reassigning during/after navigation to switch identity.

Common situations: Per-user profiles set after login while the browser is already displayed; XAML binding whose source loads asynchronously; reusing a browser instance and trying to change its session.

Related errors


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