diff --git a/libcef/browser/alloy/alloy_browser_host_impl.cc b/libcef/browser/alloy/alloy_browser_host_impl.cc index 98e1a2ce9..5d7715415 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.cc +++ b/libcef/browser/alloy/alloy_browser_host_impl.cc @@ -364,12 +364,13 @@ bool AlloyBrowserHostImpl::TryCloseBrowser() { } void AlloyBrowserHostImpl::SetFocus(bool focus) { - if (!CEF_CURRENTLY_ON_UIT()) { - CEF_POST_TASK(CEF_UIT, - base::BindOnce(&AlloyBrowserHostImpl::SetFocus, this, focus)); - return; - } + // Always execute asynchronously to work around issue #3040. + CEF_POST_TASK(CEF_UIT, base::BindOnce(&AlloyBrowserHostImpl::SetFocusInternal, + this, focus)); +} +void AlloyBrowserHostImpl::SetFocusInternal(bool focus) { + CEF_REQUIRE_UIT(); if (focus) OnSetFocus(FOCUS_SOURCE_SYSTEM); else if (platform_delegate_) diff --git a/libcef/browser/alloy/alloy_browser_host_impl.h b/libcef/browser/alloy/alloy_browser_host_impl.h index 0cac707cc..23ed06584 100644 --- a/libcef/browser/alloy/alloy_browser_host_impl.h +++ b/libcef/browser/alloy/alloy_browser_host_impl.h @@ -370,6 +370,8 @@ class AlloyBrowserHostImpl : public CefBrowserHostBase, void InitializeDevToolsRegistrationOnUIThread( CefRefPtr registration); + void SetFocusInternal(bool focus); + CefWindowHandle opener_; const bool is_windowless_; const bool is_views_hosted_;