cef icon indicating copy to clipboard operation
cef copied to clipboard

Transparent background color sometimes incorrect with system dark mode (native parent window)

Open szanto90balazs opened this issue 9 months ago • 3 comments

Describe the bug The background color I set for the browser is not always applied. The behavior is different if I navigate to a given site from another page. If the browser is created by CefBrowserHost::CreateBrowserSync into an external HWND, the issue appears. If the views framework is used and CefBrowserView::CreateBrowserView is responsible for browser creation, it works correctly.

To Reproduce Steps to reproduce the behavior:

  1. In Windows 11 OS settings, set theme to "Dark"
  2. Launch cefclient --background-color=blue
  3. Go to linkedin.com
  4. Verify that the transparent areas are filled with blue color
  5. Stop cefclient
  6. Launch cefclient --background-color=blue --use-native
  7. Go to linkedin.com
  8. See that the background color is not set to blue in the transparent areas, but it's dark
  9. Go to google.com
  10. Search for LinkedIn
  11. On the search results page, click on LinkedIn
  12. Verify that the transparent areas are filled with blue color

Expected behavior The blue background color should be applied for transparent regions in every scenario. (I used blue color for this test, but I would expect that the default background color is always white)

Actual behavior For cefclient --background-color=blue --use-native, blue is not always set as the background color

Versions (please complete the following information):

  • OS: Windows 11
  • CEF Version: 133.4.1+g02b8366+chromium-133.0.6943.142

Additional context

Does the problem reproduce with the cefclient or cefsimple sample application at the same version? Yes

Does the problem reproduce with Google Chrome at the same version? In the same version of Chrome, the background for the transparent parts are always white.

Add any other context about the problem here. See attached repro video:

https://github.com/user-attachments/assets/459c3929-3adf-47ea-a3c4-e123e944d882

szanto90balazs avatar Feb 28 '25 13:02 szanto90balazs

Just came here to open a similar issue. Overriding the background in CefWindowDelegate::OnThemeChanged does not help fix the behavior, though sometimes resizing the window after setting again the background color does cause the background to refresh.

SCA-ZMT avatar Mar 03 '25 19:03 SCA-ZMT

This seems like a regression from https://github.com/chromiumembedded/cef/issues/3459. If I comment out this line, the background will be drawn correctly with --use-native.

mikokm avatar Mar 04 '25 15:03 mikokm

Here's a patch we used to solve the issue:

Subject: [PATCH] Allow drawing webview background

---
 include/internal/cef_types.h                      | 7 +++++++
 include/internal/cef_types_wrappers.h             | 1 +
 libcef/browser/chrome/chrome_browser_host_impl.cc | 4 +++-
 3 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/include/internal/cef_types.h b/include/internal/cef_types.h
index 61551224b..972655dd5 100644
--- a/include/internal/cef_types.h
+++ b/include/internal/cef_types.h
@@ -695,6 +695,13 @@ typedef struct _cef_browser_settings_t {
   ///
   cef_color_t background_color;

+#if CEF_API_ADDED(CEF_EXPERIMENTAL)
+  ///
+  /// Controls whether the browser webview background will be drawn.
+  ///
+  cef_state_t web_view_background_visible;
+#endif
+
   ///
   /// Controls whether the Chrome status bubble will be used. Only supported
   /// with Chrome style. For details about the status bubble see
diff --git a/include/internal/cef_types_wrappers.h b/include/internal/cef_types_wrappers.h
index 11984a388..51c5879c8 100644
--- a/include/internal/cef_types_wrappers.h
+++ b/include/internal/cef_types_wrappers.h
@@ -571,6 +571,7 @@ struct CefBrowserSettingsTraits {
     target->webgl = src->webgl;

     target->background_color = src->background_color;
+    target->web_view_background_visible = src->web_view_background_visible;

     target->chrome_status_bubble = src->chrome_status_bubble;
     target->chrome_zoom_bubble = src->chrome_zoom_bubble;
diff --git a/libcef/browser/chrome/chrome_browser_host_impl.cc b/libcef/browser/chrome/chrome_browser_host_impl.cc
index 38f6ed1cc..ff71d9c93 100644
--- a/libcef/browser/chrome/chrome_browser_host_impl.cc
+++ b/libcef/browser/chrome/chrome_browser_host_impl.cc
@@ -481,7 +481,9 @@ Browser* ChromeBrowserHostImpl::CreateBrowser(
     chrome_browser_view->InitBrowser(base::WrapUnique(browser));

     // Don't set theme colors in ContentsWebView::UpdateBackgroundColor.
-    chrome_browser_view->contents_web_view()->SetBackgroundVisible(false);
+    if (params.settings.web_view_background_visible != STATE_ENABLED) {
+      chrome_browser_view->contents_web_view()->SetBackgroundVisible(false);
+    }

     // Don't show the browser by default.
     show_browser = false;

mikokm avatar Mar 04 '25 19:03 mikokm