Skip to content

WebView (Windows): fix startup flicker via --default-background-color - #26

Merged
jakepenn merged 1 commit into
minimal_masterfrom
webview-win-startup-flicker
May 22, 2026
Merged

jakepenn merged 1 commit into
minimal_masterfrom
webview-win-startup-flicker

Conversation

@jakepenn

Copy link
Copy Markdown
Member

Summary

Plugins that gate webview visibility on a first-paint handshake see a white flash on first reveal on Windows. PR #24 fixed the equivalent flicker on macOS via WKWebView's `drawsBackground = NO` KVC trick; this PR fixes the Windows side.

The existing `put_DefaultBackgroundColor` call in `setWebViewPreferences()` runs after the controller is created. By that point the renderer process can already have painted its default opaque-white frame. This patch passes the configured `WinWebView2::backgroundColour` through to the chromium renderer at process-launch time via `--default-background-color` in `ICoreWebView2EnvironmentOptions::AdditionalBrowserArguments`, so the first paint already uses the host colour.

Why this works

`AdditionalBrowserArguments` is applied when WebView2 spawns its renderer process. The chromium `--default-background-color` switch is read at renderer init, before any web content is loaded, before any frame is painted. Tauri/wry use the same approach for the same reason.

The existing post-creation `put_DefaultBackgroundColor` call stays — it covers later paints (navigation between origins, new contexts, etc.) and isn't redundant.

Test plan

  • Windows: build a Release plugin with `Options::WinWebView2{}.withBackgroundColour(host_bg)` on a webview that gates visibility on a first-paint handshake. Confirm no white flash on first reveal.
  • Windows without `withBackgroundColour`: behaviour unchanged from upstream (the default `Colour()` is transparent black, which is what the current post-creation call already requests).
  • Linux: untouched.
  • macOS: untouched.

🤖 Generated with Claude Code

Plugins that gate the WebView's visibility on a first-paint handshake see a
white flash on Windows because put_DefaultBackgroundColor is applied in
setWebViewPreferences() — *after* the controller is created and may have
already painted its default opaque-white frame.

Pass the configured WinWebView2::backgroundColour through to the chromium
renderer via --default-background-color in AdditionalBrowserArguments on
the environment options, so the renderer process is launched with our
colour already set. This mirrors the AppleWkWebView::drawsBackground = NO
trick added in #24 and addresses the same flicker pattern on Windows that
that PR fixed on macOS.

The existing post-creation put_DefaultBackgroundColor call stays — it
covers later paints (navigation, new contexts).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant