diff --git a/CefSharp.OffScreen/ChromiumWebBrowser.cs b/CefSharp.OffScreen/ChromiumWebBrowser.cs index 6d15023d7..3e8dbb3a9 100644 --- a/CefSharp.OffScreen/ChromiumWebBrowser.cs +++ b/CefSharp.OffScreen/ChromiumWebBrowser.cs @@ -40,6 +40,12 @@ namespace CefSharp.OffScreen /// private bool browserCreated; + /// + /// Action which is called immediately before the event after the + /// uderlying Chromium Embedded Framework (CEF) browser has been created. + /// + private Action onAfterBrowserCreatedDelegate; + /// /// Gets a value indicating whether this instance is disposed. /// @@ -159,9 +165,15 @@ namespace CefSharp.OffScreen /// The browser settings to use. If null, the default settings are used. /// See for more details. Defaults to null /// automatically create the underlying Browser + /// + /// Use as an alternative to the event. If the underlying Chromium Embedded Framework (CEF) browser is created successfully, + /// this action is guranteed to be called after the browser created where as the event may be called before + /// you have a chance to subscribe to the event as the CEF Browser is created async. (Issue https://github.com/cefsharp/CefSharp/issues/3552). + /// /// Cef::Initialize() failed public ChromiumWebBrowser(HtmlString html, IBrowserSettings browserSettings = null, - IRequestContext requestContext = null, bool automaticallyCreateBrowser = true) : this(html.ToDataUriString(), browserSettings, requestContext, automaticallyCreateBrowser) + IRequestContext requestContext = null, bool automaticallyCreateBrowser = true, + Action onAfterBrowserCreated = null) : this(html.ToDataUriString(), browserSettings, requestContext, automaticallyCreateBrowser, onAfterBrowserCreated) { } @@ -176,9 +188,15 @@ namespace CefSharp.OffScreen /// The browser settings to use. If null, the default settings are used. /// See for more details. Defaults to null /// automatically create the underlying Browser + /// + /// Use as an alternative to the event. If the underlying Chromium Embedded Framework (CEF) browser is created successfully, + /// this action is guranteed to be called after the browser created where as the event may be called before + /// you have a chance to subscribe to the event as the CEF Browser is created async. (Issue https://github.com/cefsharp/CefSharp/issues/3552). + /// /// Cef::Initialize() failed public ChromiumWebBrowser(string address = "", IBrowserSettings browserSettings = null, - IRequestContext requestContext = null, bool automaticallyCreateBrowser = true) + IRequestContext requestContext = null, bool automaticallyCreateBrowser = true, + Action onAfterBrowserCreated = null) { if (!Cef.IsInitialized) { @@ -194,6 +212,7 @@ namespace CefSharp.OffScreen Cef.AddDisposable(this); Address = address; + onAfterBrowserCreatedDelegate = onAfterBrowserCreated; managedCefBrowserAdapter = ManagedCefBrowserAdapter.Create(this, true); @@ -658,6 +677,7 @@ namespace CefSharp.OffScreen /// The browser. partial void OnAfterBrowserCreated(IBrowser browser) { + onAfterBrowserCreatedDelegate?.Invoke(browser); BrowserInitialized?.Invoke(this, EventArgs.Empty); }