electron: [Bug]: The “backgroundColor” does not take effect immediately when the window is displayed

Preflight Checklist

Electron Version

31.0.1

What operating system are you using?

macOS

Operating System Version

14.5 (23F79)

What arch are you using?

arm64 (including Apple Silicon)

Last Known Working Electron version

No response

Expected Behavior

  const mainWindow = new BrowserWindow({
    width: 900,
    height: 670,
    show: false,
    autoHideMenuBar: true,
    backgroundColor: '#141414',
    ...(process.platform === 'linux' ? { icon } : {}),
    webPreferences: {
      preload: join(__dirname, '../preload/index.js'),
      sandbox: false
    }
  })

After creating the window, the background color should be “#141414”.

Actual Behavior

The moment the window is displayed, the background color is white and immediately changes to “#141414”.

Testcase Gist URL

No response

Additional Information

No response

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 5
  • Comments: 24 (2 by maintainers)

Commits related to this issue

Most upvoted comments

I might add here that this seems to happen even when delaying showing the window after the ready-to-show event has been fired. When the window is shown, it flashes white first, even if the page in it has been loaded.

Seeing this is affecting more than macOS and multiple people have confirmed it, meaning it’s an actual problem, can this issue be tagged appropriately and prioritised? I’m sticking with v29 until this issue is sorted out, which isn’t an ideal situation. It’s a show-stopper for me.

Linux as well.

This works on linux, but not on windows.

app.whenReady().then(async () => {
  await new Promise((resolve) => setTimeout(resolve)); // workaround to reduce flicker in linux
  createWindow();
  app.on("activate", () => {
    if (BrowserWindow.getAllWindows().length === 0) {
      createWindow();
    }
  });
});

Update: In my research, use ESModule on Linux needs this workaround, but CommonJS doesn’t. May be related with https://github.com/electron/electron/issues/40719 .

I know why VSCode in windows doesn’t have this problem. It use { titleBarStyle: "hidden", titleBarOverlay: true }. And the frameless window with controls will not show white background. Instead, it shows a transparent background.

I also defer showing the window until after the ready-to-show event has fired. It still flashes white for me. Even putting a delay after the event had fired with setTimeout still has a white flash. It appears that the process of showing the window causes it, even if the page has fully loaded. This problem may have started as far back as Electron 29, though I see if only on the very rare occasion on that version.

I’ve just tested on Windows 11 23H2, and it happens there. So it’s not isolated to macOS.

I am also seeing this issue. It only happens upon the first initial show. It does not happen upon subsequent shows, where the background color is respected). The window is completely empty, not even native controls are shown.

Elmedia Player - 2024-07-26 at 16 12 30@2x Elmedia Player - 2024-07-26 at 16 12 24@2x

I went into detail in a SO question.