{"record":{"id":"fe50e9fa3cfbffe9","repo":"cefsharp/CefSharp","slug":"the-chromiumwebbrowser-instance-creates-the-underl-fe50e9","errorCode":null,"errorMessage":"The ChromiumWebBrowser instance creates the underlying Chromium Embedded Framework (CEF) browser instance in an async fashion. The undelying CefBrowser instance is not yet initialized. Use the IsBrowserInitializedChanged event and check the IsBrowserInitialized property to determine when the browser has been initialized.","messagePattern":"The ChromiumWebBrowser instance creates the underlying Chromium Embedded Framework \\(CEF\\) browser instance in an async fashion\\. The undelying CefBrowser instance is not yet initialized\\. Use the IsBrowserInitializedChanged event and check the IsBrowserInitialized property to determine when the browser has been initialized\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs","lineNumber":555,"sourceCode":"        /// Check is browser is initialized\n        /// </summary>\n        /// <returns>true if browser is initialized</returns>\n        private bool InternalIsBrowserInitialized()\n        {\n            // Use CompareExchange to read the current value - if disposeCount is 1, we set it to 1, effectively a no-op\n            // Volatile.Read would likely use a memory barrier which I believe is unnecessary in this scenario\n            return Interlocked.CompareExchange(ref browserInitialized, 0, 0) == 1;\n        }\n\n        /// <summary>\n        /// Throw exception if browser not initialized.\n        /// </summary>\n        /// <exception cref=\"Exception\">Thrown when an exception error condition occurs.</exception>\n        private void ThrowExceptionIfBrowserNotInitialized()\n        {\n            if (!InternalIsBrowserInitialized())\n            {\n                throw new Exception(BrowserNotInitializedExceptionErrorMessage);\n            }\n        }\n\n        /// <summary>\n        /// Throw exception if disposed.\n        /// </summary>\n        /// <exception cref=\"ObjectDisposedException\">Thrown when a supplied object has been disposed.</exception>\n        private void ThrowExceptionIfDisposed()\n        {\n            if (IsDisposed)\n            {\n                throw new ObjectDisposedException(\"ChromiumWebBrowser\");\n            }\n        }\n\n        private int GetChromiumChildProcessId(string frameIdentifier)\n        {\n            try","sourceCodeStart":537,"sourceCodeEnd":573,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp/Internals/Partial/ChromiumWebBrowser.Partial.cs#L537-L573","documentation":"Thrown by ThrowExceptionIfBrowserNotInitialized when a member that requires the underlying CefBrowser is accessed before the browser has finished its async initialization. ChromiumWebBrowser creates the CEF browser asynchronously, so accessing browser-dependent APIs immediately after construction fails. The message directs you to the IsBrowserInitializedChanged event and IsBrowserInitialized property.","triggerScenarios":"Calling Load(), GetBrowser(), ExecuteScriptAsync(), or similar immediately after `new ChromiumWebBrowser(...)` in the same synchronous block, before IsBrowserInitialized becomes true.","commonSituations":"Constructing the browser and calling Load in the same constructor/Loaded handler; headless (OffScreen) usage that does not wait for initialization; tests that act on the browser too early.","solutions":["Subscribe to IsBrowserInitializedChanged and perform browser-dependent work only when IsBrowserInitialized is true.","Await the appropriate initialization task/awaitable your ChromiumWebBrowser host exposes before calling browser APIs.","For OffScreen, await the initialization completion before loading content.","Move Load/exec calls into an initialized callback rather than the constructor."],"exampleFix":"// before\nvar browser = new ChromiumWebBrowser(url);\nbrowser.ExecuteScriptAsync(\"doStuff()\"); // not initialized yet\n\n// after\nvar browser = new ChromiumWebBrowser(url);\nbrowser.IsBrowserInitializedChanged += (s, e) =>\n{\n    if (browser.IsBrowserInitialized)\n        browser.ExecuteScriptAsync(\"doStuff()\");\n};","handlingStrategy":"validation","validationCode":"if (!browser.IsBrowserInitialized)\n{\n    var tcs = new TaskCompletionSource<bool>();\n    browser.IsBrowserInitializedChanged += (s, e) =>\n    {\n        if (browser.IsBrowserInitialized) tcs.TrySetResult(true);\n    };\n    await tcs.Task;\n}\n// browser is now ready","typeGuard":null,"tryCatchPattern":"try { browser.Load(url); }\ncatch (Exception ex) when (ex.Message.Contains(\"not yet initialized\"))\n{ /* wait for IsBrowserInitialized, then retry once */ }","preventionTips":["Subscribe to IsBrowserInitializedChanged before doing browser-dependent work.","Await the host's initialization awaitable (e.g. OffScreen) before Load/exec.","Avoid calling browser APIs in the same synchronous block as construction."],"tags":["cefsharp","initialization","async","browser-lifecycle","timing"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}