{"record":{"id":"f5cbf33e3d063b36","repo":"cefsharp/CefSharp","slug":"browser-has-already-been-created-requestcontext-m","errorCode":null,"errorMessage":"Browser has already been created. RequestContext must be set before the underlying CEF browser is created.","messagePattern":"Browser has already been created\\. RequestContext must be set before the underlying CEF browser is created\\.","errorType":"exception","errorClass":"Exception","httpStatus":null,"severity":"error","filePath":"CefSharp.WinForms/ChromiumWebBrowser.cs","lineNumber":155,"sourceCode":"        /// Activates browser upon creation, the default value is false. Prior to version 73\n        /// the default behaviour was to activate browser on creation (Equivalent of setting this property to true).\n        /// To restore this behaviour set this value to true immediately after you create the <see cref=\"ChromiumWebBrowser\"/> instance.\n        /// https://github.com/chromiumembedded/cef/issues/1856\n        /// </summary>\n        public bool ActivateBrowserOnCreation { get; set; }\n        /// <summary>\n        /// Gets or sets the request context.\n        /// </summary>\n        /// <value>The request context.</value>\n        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(null)]\n        public IRequestContext RequestContext\n        {\n            get { return requestContext; }\n            set\n            {\n                if (browserCreated)\n                {\n                    throw new Exception(\"Browser has already been created. RequestContext must be \" +\n                                        \"set before the underlying CEF browser is created.\");\n                }\n                if (value != null && !Core.ObjectFactory.RequestContextType.IsAssignableFrom(value.UnWrap().GetType()))\n                {\n                    throw new Exception(string.Format(\"RequestContext can only be of type {0} or null\", Core.ObjectFactory.RequestContextType));\n                }\n                requestContext = value;\n            }\n        }\n        /// <summary>\n        /// A flag that indicates whether the control is currently loading one or more web pages (true) or not (false).\n        /// </summary>\n        /// <value><c>true</c> if this instance is loading; otherwise, <c>false</c>.</value>\n        /// <remarks>In the WPF control, this property is implemented as a Dependency Property and fully supports data\n        /// binding.</remarks>\n        [Browsable(false), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden), DefaultValue(false)]\n        public bool IsLoading { get; private set; }\n        /// <summary>","sourceCodeStart":137,"sourceCodeEnd":173,"githubUrl":"https://github.com/cefsharp/CefSharp/blob/16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec/CefSharp.WinForms/ChromiumWebBrowser.cs#L137-L173","documentation":"Thrown by the WinForms ChromiumWebBrowser.RequestContext setter when the underlying CEF browser has already been created. The RequestContext (cookie/cache隔离, proxy, preferences partition) is bound at browser creation time in CEF and cannot be changed afterward, so the setter rejects late assignment once browserCreated is true.","triggerScenarios":"Setting RequestContext after the control handle was created (form shown, Controls.Add realized the handle, Load called, or handle recreated). Same window as the BrowserSettings error but for the request/identity context.","commonSituations":"Trying to switch a user/session identity (incognito, separate cookie jar, per-tab proxy) after the browser is already on screen; setting it in Form.Load; reassigning after navigation has started.","solutions":["Assign RequestContext immediately after `new ChromiumWebBrowser(...)`, before the control is parented/shown.","For per-session isolation, create the RequestContext first, build the browser with it, then parent the control.","To change identity at runtime, dispose the current ChromiumWebBrowser and create a new one with a fresh RequestContext rather than reassigning the property.","Avoid touching .Handle or adding to a visible parent before the assignment."],"exampleFix":"// before\nvar browser = new ChromiumWebBrowser();\nthis.Controls.Add(browser);\nbrowser.RequestContext = new RequestContext(new RequestContextSettings { CachePath = \"profileA\" }); // throws\n\n// after\nvar rc = new RequestContext(new RequestContextSettings { CachePath = \"profileA\" });\nvar browser = new ChromiumWebBrowser { RequestContext = rc };\nthis.Controls.Add(browser);","handlingStrategy":"validation","validationCode":"if (!browser.IsBrowserInitialized)\n{\n    browser.RequestContext = new RequestContext(new RequestContextSettings { CachePath = path });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Build the RequestContext first, then construct/assign before the control handle is created.","To switch identity at runtime, recreate the ChromiumWebBrowser instead of reassigning.","Never access browser.Handle before assigning RequestContext."],"tags":["cefwsharp","winforms","lifecycle","request-context"],"backgroundTag":null,"analyzedSha":"16bc6e0711a4945be17e8bc4bc7ccf9469f3fdec","analyzedAt":"2026-08-13T19:57:05.828Z","schemaVersion":2},"datasetVersion":"2026-08-14T00:17:13.853Z"}