cefsharp/CefSharp · error · Exception
RequestContext is null, unable to obtain cookie manager
Error message
RequestContext is null, unable to obtain cookie manager
What it means
GetCookieManager reaches into the browser host's RequestContext to obtain the cookie manager. If host.RequestContext is null, the browser has no request context attached, so there is no cookie manager to return and the method throws. This typically indicates the browser host is not yet fully initialized or the context was never set.
Source
Thrown at CefSharp/WebBrowserExtensions.cs:1164
/// <param name="browser">The ChromiumWebBrowser instance this method extends.</param>
/// <param name="callback">(Optional) If not null it will be executed asynchronously on the CEF IO thread after the manager's
/// storage has been initialized.</param>
/// <returns>
/// Cookie Manager.
/// </returns>
public static ICookieManager GetCookieManager(this IChromiumWebBrowserBase browser, ICompletionCallback callback = null)
{
ThrowExceptionIfChromiumWebBrowserDisposed(browser);
var host = browser.GetBrowserHost();
ThrowExceptionIfBrowserHostNull(host);
var requestContext = host.RequestContext;
if (requestContext == null)
{
throw new Exception("RequestContext is null, unable to obtain cookie manager");
}
return requestContext.GetCookieManager(callback);
}
/// <summary>
/// Gets the RequestContext associated with the <see cref="IChromiumWebBrowserBase"/> instance.
/// </summary>
/// <exception cref="Exception">Thrown when an exception error condition occurs.</exception>
/// <param name="browser">The ChromiumWebBrowser instance this method extends.</param>
/// <returns>
/// RequestContext
/// </returns>
public static IRequestContext GetRequestContext(this IChromiumWebBrowserBase browser)
{
ThrowExceptionIfChromiumWebBrowserDisposed(browser);
var host = browser.GetBrowserHost();View on GitHub (pinned to 16bc6e0711)
Solutions
- Wait until the browser is initialized (e.g. subscribe to IsBrowserInitializedChanged / LoadingStateChanged and call GetCookieManager only after IsBrowserInitialized is true) before requesting the cookie manager.
- If you need the cookie manager before the browser is created, obtain it from the RequestContext you assigned to the browser via requestContext.GetCookieManager().
- Guard with a null check on host?.RequestContext before calling.
- Ensure a RequestContext is passed to the ChromiumWebBrowser constructor if you rely on a specific profile.
Example fix
// before
var mgr = browser.GetCookieManager(); // throws if RequestContext null
// after: wait for init, then guard
if (browser.IsBrowserInitialized)
{
var host = browser.GetBrowserHost();
if (host?.RequestContext != null)
{
var mgr = host.RequestContext.GetCookieManager();
}
} Defensive patterns
Strategy: validation
Validate before calling
var host = browser?.GetBrowserHost();
var rc = host?.RequestContext;
if (rc != null)
{
var mgr = rc.GetCookieManager();
} Type guard
static bool HasRequestContext(IChromiumWebBrowserBase browser) =>
browser?.GetBrowserHost()?.RequestContext != null; Prevention
- Call GetCookieManager only after IsBrowserInitialized is true.
- Where possible, get the cookie manager from the RequestContext you constructed rather than from the host.
- Avoid touching cookies during disposal.
When it happens
Trigger: Calling browser.GetCookieManager() when browser.GetBrowserHost() returns a host whose RequestContext property is null - usually too early in the browser lifecycle (before the underlying CEF browser is created) or in headless/OffScreen scenarios where initialization is incomplete.
Common situations: Calling GetCookieManager immediately after constructing a ChromiumWebBrowser (before the Rendering/Loading phase). Unit tests or OffScreen usage where the browser hasn't finished initializing. Disposing sequences where the host exists but its context was torn down.
Related errors
- CookieManager store is not initialized.
- IFrame instance is null. Browser has likely not finished ini
- IBrowserHost instance is null. Browser has likely not finish
- IBrowser
- Unable to invoke ExecuteDevToolsMethod on CEF UI Thread.
AI-assisted analysis of cefsharp/CefSharp@16bc6e0711 (2026-08-13).
Data as JSON: /api/errors/764e358ad217b623.
Report an issue: GitHub.