Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: BrowserWindow backgroundColor doesn't work in Electron 14 and 15 #30759

Closed
3 tasks done
samuelmaddock opened this issue Aug 30, 2021 · 8 comments · Fixed by #30778
Closed
3 tasks done

[Bug]: BrowserWindow backgroundColor doesn't work in Electron 14 and 15 #30759

samuelmaddock opened this issue Aug 30, 2021 · 8 comments · Fixed by #30778
Assignees
Labels
14-x-y 15-x-y bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS platform/windows status/confirmed A maintainer reproduced the bug or agreed with the feature

Comments

@samuelmaddock
Copy link
Member

samuelmaddock commented Aug 30, 2021

Preflight Checklist

Electron Version

14.0.0-beta.11

What operating system are you using?

Windows

Operating System Version

Windows 10 21H1, macOS 11.5.1

What arch are you using?

x64

Last Known Working Electron version

14.0.0-beta.10

Expected Behavior

Creating a BrowserWindow with the backgroundColor option results in the new window displaying that color behind the transparent WebContents.

Actual Behavior

Creating a BrowserWindow with the backgroundColor option results in the new window displaying a white background color behind the transparent WebContents.

Testcase Gist URL

https://gist.github.com/4256f388d41ef0d974645a11ab72b1fe

Additional Information

The problematic version was discovered using Electron Fiddle's bisect feature.
v14.0.0-beta.10...v14.0.0-beta.11

#30136 seems related

I'm not seeing this behavior in a testing build of current main (8007d01).

I'm looking into a fix, will update as progress is made.

@samuelmaddock samuelmaddock added platform/windows platform/macOS bug 🪲 status/confirmed A maintainer reproduced the bug or agreed with the feature has-repro-gist Issue can be reproduced with code at https://gist.github.com/ 14-x-y 15-x-y labels Aug 30, 2021
@codebytere
Copy link
Member

codebytere commented Aug 31, 2021

@samuelmaddock this appears to only be happening within a certain range 🤔 it works properly on 16.0.0-nightly.20210727 and beyond.

v16.0.0-nightly.20210726...v16.0.0-nightly.20210727

@andmm
Copy link

andmm commented Aug 31, 2021

Same bug here on 14.0.0 final on win 7.

@samuelmaddock
Copy link
Member Author

@samuelmaddock this appears to only be happening within a certain range 🤔 it works properly on 16.0.0-nightly.20210727 and beyond.

v16.0.0-nightly.20210726...v16.0.0-nightly.20210727

It's fixed after the introduction of #30193

@samuelmaddock samuelmaddock changed the title [Bug]: BrowserWindow backgroundColor doesn't work in Electron >=14 [Bug]: BrowserWindow backgroundColor doesn't work in Electron 14 and 15 Aug 31, 2021
@samuelmaddock samuelmaddock self-assigned this Aug 31, 2021
@samuelmaddock
Copy link
Member Author

This works:

// Set the background color of RenderWidgetHostView.
auto* web_preferences = WebContentsPreferences::From(web_contents());
if (web_preferences) {
std::string color_name;
rwhv->SetBackgroundColor(web_preferences->GetBackgroundColor());
}

This does not work:

-rwhv->SetBackgroundColor(web_preferences->GetBackgroundColor()); 
+rwhv->SetBackgroundColor(SK_ColorRED);

🤔🤔🤔

@samuelmaddock
Copy link
Member Author

Sometimes on startup, you can see the correct background color set, then immediately gets replaced with a white background color. I believe initially it shows the native window color followed by the RenderWidgetHostView's background.

Setting the background to transparent allows the native window's background color to show up:

rwhv->SetBackgroundColor(SK_ColorTRANSPARENT);

#30193 may have actually broken web_preferences->GetBackgroundColor() causing it to always return a background color value of 0 (fully transparent). On Electron v16, the "fixed" background color we're actually seeing is the background of the native window.

@samuelmaddock
Copy link
Member Author

The white background color is coming from the page background color defined in Blink: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/exported/web_view_impl.cc;l=3049-3058;drc=98898daa2e8f46ff098cea1f2e218f8a8266c838

  // Use the page background color if this is the WebView of the main frame.
  if (MainFrameImpl())
    return page_base_background_color_;

To update this color, we need to call WebContents::SetPageBaseBackgroundColor(). This was reverted in #30136 which we'll need to pay special attention to with a fix.

@samuelmaddock
Copy link
Member Author

#30777 will solve the problem for Electron 14 and 15. main will need a separate PR since the WebPreferences refactor makes the code quite a bit different.

@jkleinsc
Copy link
Contributor

jkleinsc commented Sep 7, 2021

@andmm your comment was deleted as a violation of the Electron Code of Conduct. You may consider this an official warning.

Please do not interact with the project for 24 hours. After that, please look through your open issues and edit them to ensure they're entirely on-topic, and we can continue the discussion here about the best way to go forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
14-x-y 15-x-y bug 🪲 has-repro-gist Issue can be reproduced with code at https://gist.github.com/ platform/macOS platform/windows status/confirmed A maintainer reproduced the bug or agreed with the feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants