electron: [Bug]: window transparency not respected (black/gray background) on some systems

Preflight Checklist

Electron Version

25, 26, 27, 31, 33, 34

What operating system are you using?

Windows

Operating System Version

Windows 10, Windows 11

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

When setting these options on a new BrowserWindow, the window should always be transparent regardless of whether or not hardware acceleration is enabled:

new BrowserWindow({
  frame: false,
  transparent: true,
  alwaysOnTop: true
})

image

Actual Behavior

For some reason, for some people, electron does not respect the transparency or a transparent background color (such as #00000000) and it has a black background when hardware acceleration is enabled. image

For some users, disabling hardware acceleration fixes it. Similar to this issue it seems.

Testcase Gist URL

https://gist.github.com/Galkon/c5e195442696a324afa03d9c391e8893 Sample App

Additional Information

Context

Context: We are using electron for a screen overlay at Medal.tv. For everyone on our team, there are no issues with transparency. However, there are some users using our production app which have this issue.

In our app we are still using electron 22 for win 7/8/8.1 compatibility, but I have verified this problem still exists in 25, 26, and 27 (side note, 27 is plagued by this bug too).

Disabling hardware acceleration is a less-than-ideal solution because our app is video-based and you cannot disable it per-window, only for the entire app.

Debugging

I’ve created a sample app which currently can run 15 different test scenarios, all of which still produce a black window for affected users when it should be transparent.

The tests it runs include 15 variations of the following:

  • Setting the window size to be smaller than display width / height (mentioned in this issue)
  • backgroundColor set to #00000000 or not set (related issue here?)
  • Delaying window show vs show: true on BrowserWindow initialization
  • Disabling thickFrame
  • Setting backgroundMaterial to none
  • Setting hasShadow to false
  • Calling setBackground('#00000000') after initialization
  • Manually controlling window size via setBounds and setContentSize
  • Manually calling setAlwaysOnTop after initialization

System Specs

I’ve been able to grab some specs of users systems, but I cannot find any correlating factors. It has happened to users on Windows 10, Windows 11, users with a single monitor, users with multiple monitors.

Windows Version (os.release()) CPU GPU(s) Number of displays Display resolution(s)
10.0.19045 Intel® Core™ i7-3770 CPU @ 3.40GHz NVIDIA GeForce GTX 1060 6GB 1 1280x1024
10.0.22621 12th Gen Intel® Core™ i5-12600KF NVIDIA GeForce RTX 3080 2 2560x1080, 1920x1080
10.0.19045 AMD Ryzen 5 5600X 6-Core Processor NVIDIA GeForce RTX 3070 1 1920x1080
10.0.22621 Intel® Core™ i5-10400F CPU @ 2.90GHz NVIDIA GeForce GTX 1650 1 1920x1080
10.0.19045 Intel® Core™ i5-10400 CPU @ 2.90GHz NVIDIA GeForce GTX 1080 Ti, Intel® UHD Graphics 630 1 1920x1080
10.0.22621 AMD Ryzen 5 5600G with Radeon Graphics NVIDIA GeForce RTX 3060 1 1920x1080
10.0.22621 AMD Ryzen 7 7700X 8-Core Processor AMD Radeon™ Graphics 3 1920x1080, 2560x1440, 1080x1920
10.0.22631 12th Gen Intel® Core™ i5-12400 Intel® UHD Graphics 730 1 1920x1080
10.0.22631 Intel® Core™ i7-10700KF CPU @ 3.80GHz NVIDIA GeForce RTX 3070 1 1920x1080

Other Info

  • It appears to happen regardless of windows display scaling setting (happens at 100%)
  • It appears to happen regardless of whether has an integrated GPU or not
  • One user did reinstall Windows 10 after they ran into this on Windows 11, and it was fixed for them. So it seems to me that it is a software issue under certain circumstances that I haven’t pinpointed yet.

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 4
  • Comments: 32 (4 by maintainers)

Most upvoted comments

bump

Image

reproduced on another user’s computer

associated issue: https://github.com/std-microblock/breeze-shell/issues/1

I reproduced this issue with bare GLFW and OpenGL, the code is here: https://gist.github.com/std-microblock/2d7cb4ed154ed8969d0ca5ec755fa799 This might be the most simple reproducer

@Galkon does it occur in Chrome or only Electron apps? I have #43122 which isn’t the same, but I suspect there could be the same root cause. It only happens on select Nvidia cards (but haven’t tested AMD), only on Windows, and only with Electron (Chrome is 100% fine.)

Not sure, I don’t know how to test a transparent frameless window with Chrome alone 😅

We have had tens of thousands of users at Medal.tv run into this issue, which is for windows only. Some users have it fixed by tweaking nvidia settings and others have no such luck or don’t have an nvidia gpu.

It’s unlikely a solely Chromium or nVidia issue. I happen to run into exactly same problem on bare-bone WinAPI app written in Rust under 500 LOC with simple layered window (in fact, the search for the solution happen to drive me here from Google). No chromium involved. And I know of report in the wild from AMD GPUs.

Hello, I just happen to run into very same problem with different WinAPI application (my own actually, Rust based with OpenGL renderer). It happen on my PC, and after googling a lot I found this page, so I wish to to share some of my insights:

  1. The problem disappear completely (transparency is preserved) if the window does not have focus at start - but it will reappear as soon as it is focused (resulting in opaque window) and stays opaque even if losing focus again (correction: losing focus again retriggers correct transparency)
  2. Any form of redrawing anything, including RedrawWindow(NULL, ...) (this should redraw entire desktop) has utter no effect.
  3. Any form of invalidation has utter no effect
  4. My attempt to loop hide-and-show the entire resulted in heavy shuttering at desktop and I am unable to verify if this has any effect
  5. Calling UpdateLayeredWindow() per frame (also with non-NULL args containing unchanged position or size) has utter no effect
  6. Calling SetLayeredWindowAttributes per frame has also no effect
  7. Setting width or height to anything but desktop size WILL result in preserving the transparency of layered window (workaround the issue)
  8. AND: I observed a strange visual artifact. Setting width/height to desktop size hides taskbar (as desired), but setting to any other value - even 1 pixel apart - will keep the taskbar visible
  9. This leads me to believe there is some setting regarding borderless fullscreen gaming, but I was unable to find actual one.
  10. More info soon…

Platform: nVidia GeForce / Win 11 <- both up to date