Skip to content

[Problem/Bug]: Setting PreferredColorScheme on ICoreWebView2Profile4 affects all WebViews in the same Environment #5457

@zprettytext

Description

@zprettytext

What happened?

Bug Report: Setting PreferredColorScheme on ICoreWebView2Profile4 affects all WebViews in the same Environment
Reproduction Steps

Create a WebView2 Environment

auto hr = CreateCoreWebView2EnvironmentWithOptions(...);

Create WebView #1 and set LIGHT theme

2.1 webViewEnvironment10->CreateCoreWebView2ControllerWithOptions(...)
2.2 In the controller-created callback:
    HRESULT OnCreatedWebViewController(HRESULT result, ICoreWebView2Controller* controller, int clientBrowserId)


Inside the callback:

auto webView2_13 = webviewWindow_.try_query<ICoreWebView2_13>();
auto webView2Profile4 = webView2Profile.try_query<ICoreWebView2Profile4>();
webView2Profile4->put_PreferredColorScheme(COREWEBVIEW2_PREFERRED_COLOR_SCHEME_LIGHT);

Create WebView #2 and set DARK theme

3.1 webViewEnvironment10->CreateCoreWebView2ControllerWithOptions(...)
3.2 In the controller-created callback:
    HRESULT OnCreatedWebViewController(HRESULT result, ICoreWebView2Controller* controller, int clientBrowserId)


Inside the callback:

auto webView2_13 = webviewWindow_.try_query<ICoreWebView2_13>();
auto webView2Profile4 = webView2Profile.try_query<ICoreWebView2Profile4>();
webView2Profile4->put_PreferredColorScheme(COREWEBVIEW2_PREFERRED_COLOR_SCHEME_DARK);

Expected Behavior

WebView #1 should use LIGHT theme.

WebView #2 should use DARK theme.

Each WebView instance should respect its own ICoreWebView2Profile4::PreferredColorScheme.

Actual Behavior

WebView #1 → DARK theme (incorrect)

WebView #2 → DARK theme (correct)

Setting PreferredColorScheme on the profile for WebView #2 unexpectedly changes the theme of WebView #1 as well.

Conclusion

This appears to be a bug:

ICoreWebView2Profile4::put_PreferredColorScheme modifies the color scheme for all WebViews created from the same WebView2Environment, rather than only the WebView associated with that profile.

Desired Behavior

PreferredColorScheme should apply only to the specific WebView/Profile instance, and should not affect other WebViews created from the same WebView2Environment.

This is important for applications that host multiple WebViews with different theme requirements.

Importance

Blocking. My app's basic functions are not working due to this issue.

Runtime Channel

Stable release (WebView2 Runtime)

Runtime Version

138.0.3351.83

SDK Version

No response

Framework

Win32

Operating System

Windows 11

OS Version

No response

Repro steps

Create a WebView2Environment

auto hr = CreateCoreWebView2EnvironmentWithOptions();

Create WebView #1 and set it to LIGHT theme

Call CreateCoreWebView2ControllerWithOptions

After WebView is created, get its ICoreWebView2Profile4

Set:

webView2Profile2_->put_PreferredColorScheme(
COREWEBVIEW2_PREFERRED_COLOR_SCHEME_LIGHT);

Create WebView #2 and set it to DARK theme

Call CreateCoreWebView2ControllerWithOptions

After WebView is created, get its ICoreWebView2Profile4

Set:

webView2Profile2_->put_PreferredColorScheme(
COREWEBVIEW2_PREFERRED_COLOR_SCHEME_DARK);

Expected Result

WebView #1 should use LIGHT theme

WebView #2 should use DARK theme

Actual Result

WebView #1 becomes DARK

WebView #2 becomes DARK

Setting the theme on WebView #2 changes the theme of WebView #1.

Conclusion (Bug Summary)

This is a bug:
Setting PreferredColorScheme on ICoreWebView2Profile4 affects all WebViews created from the same WebView2Environment, instead of applying only to the specific WebView/profile.

Expected behavior:
Changing the theme on a profile should not modify the theme of other WebViews in the same environment.

Repros in Edge Browser

Yes, issue can be reproduced in the corresponding Edge version

Regression

No, this never worked

Last working version (if regression)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions