Closed albianto closed 5 months ago
This would require pretty significant Chromium changes, and is therefore not something that we are likely to implement for CEF.
With Chrome runtime you can configure this using themes (see here). That likely equates to the browser.theme.color_scheme
(prefs::kBrowserColorScheme) preference that can be configured via CefPreferenceManager. Supported integer values are listed in ThemeService::BrowserColorScheme.
Setting the preference directly during runtime may not be enough. It may be necessary to instead call ThemeService::SetBrowserColorScheme which sets the preference and then triggers notifications.
Setting the preference directly during runtime may not be enough. It may be necessary to instead call ThemeService::SetBrowserColorScheme which sets the preference and then triggers notifications.
I've tried setting the browser.theme.color_scheme preference from within code and it is not working like suspected.
Is it possible to call into ThemeService from within CEF or is it functionality that would need to be added?
Is it possible to call into ThemeService from within CEF or is it functionality that would need to be added?
It is possible from within CEF (with Chrome runtime) but it is not yet exposed to client applications.
Is it possible to call into ThemeService from within CEF or is it functionality that would need to be added?
It is possible from within CEF (with Chrome runtime) but it is not yet exposed to client applications.
It would be really appreciated if this feature could be added. I guess for now, the best alternative is to inject javascript from the application that sets different body classes for light and dark modes rather than relying on "prefers-color-scheme".
Related bug with Chrome not applying dynamic light/dark mode changes to web content: https://issues.chromium.org/issues/332328864
@magreenblatt does this completed change now mean we can change the colour scheme web-content is rendered in or is it limited to the colour of the window chrome? E.g. Can we control whether "prefer-color-scheme: light" or "prefer-color-scheme: dark" is applied?
Can we control whether "prefer-color-scheme: light" or "prefer-color-scheme: dark" is applied?
Yes, but only in combination with setting the OS or Chrome theme. It cannot be set independently.
@magreenblatt Thanks for working on this. Really appreciate the effort! I tested CefRequestContext::SetChromeColorScheme and I was wondering if there's a way to have the new color scheme be applied to an already loaded page. It works just fine after the page is reloaded.
Is your feature request related to a problem? Please describe. We have a cross-platform application that has a runtime setting that lets the user switch between light and dark themes. The user can choose to either follow the OS setting or override it. We can force CEF to run in light or dark mode at launch with the force-light/dark command line flags. We cannot however set these after launch.
Describe the solution you'd like We would like to be able to change the active CEF theme at runtime. We'd love to have an API on CefBrowser that would let us do this.