cefsharp/CefSharp · error · Exception

Browser has not yet finished initializing or is being…

Error message

Browser has not yet finished initializing or is being disposed

What it means

Thrown by the example ChromiumWebBrowserWithScreenshotSupport.TakeScreenshot when IsBrowserInitialized is false. Capture works by resizing the off-screen browser and reading the rendered frame in OnPaint; if the browser has not finished initializing (or is being disposed) there is no renderer to produce a frame, so capture is rejected up front.

Solutions

  1. Wait until IsBrowserInitialized is true (subscribe to IsBrowserInitializedChanged or await initialization) before calling TakeScreenshot.
  2. Guard with `if (browser.IsBrowserInitialized)` and disable the capture command until initialized.
  3. Cancel any pending capture when the control starts disposing.
  4. Ensure the browser has a loaded/committed page before capturing.

Example fix

// before
public MainWindow()
{
    browser = new ChromiumWebBrowserWithScreenshotSupport();
    var shot = browser.TakeScreenshot(size); // throws: not initialized
}

// after
browser.IsBrowserInitializedChanged += (s, e) =>
{
    if (browser.IsBrowserInitialized)
        _ = browser.TakeScreenshot(size);
};
Defensive patterns

Strategy: validation

Validate before calling

if (browser.IsBrowserInitialized)
{
    _ = browser.TakeScreenshot(size);
}

Prevention

When it happens

Trigger: Calling TakeScreenshot before the browser finished its initial creation; calling during shutdown while the browser is disposing.

Common situations: Wiring the screenshot to a window Loaded event that fires before CEF reports IsBrowserInitialized; capturing immediately after setting Address; capturing during app exit.

Related errors


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

Appendix: source

Thrown at CefSharp.Wpf.Example/Controls/ChromiumWebBrowserWithScreenshotSupport.cs:56

        private CancellationTokenRegistration? cancellationTokenRegistration;

        public ICommand ScreenshotCommand { get; set; }

        public ChromiumWebBrowserWithScreenshotSupport() : base()
        {
            ScreenshotCommand = new RelayCommand(TakeScreenshot);
        }

        public Task<InteropBitmap> TakeScreenshot(Size screenshotSize, int? frameRate = 1, int? ignoreFrames = 0, CancellationToken? cancellationToken = null)
        {
            if (screenshotTaskCompletionSource != null && screenshotTaskCompletionSource.Task.Status == TaskStatus.Running)
            {
                throw new Exception("Screenshot already in progress, you must wait for the previous screenshot to complete");
            }

            if (IsBrowserInitialized == false)
            {
                throw new Exception("Browser has not yet finished initializing or is being disposed");
            }

            if (IsLoading)
            {
                throw new Exception("Unable to take screenshot while browser is loading");
            }

            var browserHost = this.GetBrowserHost();

            if (browserHost == null)
            {
                throw new Exception("IBrowserHost is null");
            }

            screenshotTaskCompletionSource = new TaskCompletionSource<InteropBitmap>(TaskCreationOptions.RunContinuationsAsynchronously);

            if (cancellationToken.HasValue)
            {

View on GitHub (pinned to 16bc6e0711)