Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/windows-default-bg-color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
wry: patch
---

On Windows on systems running WebView2 v137+ wry now uses a new default background color API which should reduce white flashes. The use of the `RemoveRedirectionBitmap` browser flag (v134+) was removed due to crashes on Insider builds.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ pub trait WebViewBuilderExtWindows {
/// ## Warning
///
/// - Webview instances with different browser arguments must also have different [data directories](struct.WebContext.html#method.new).
/// - By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --enable-features=RemoveRedirectionBitmap`
/// - By default wry passes `--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection`
/// `--autoplay-policy=no-user-gesture-required` if autoplay is enabled
/// and `--proxy-server=<scheme>://<host>:<port>` if a proxy is set.
/// so if you use this method, you have to add these arguments yourself if you want to keep the same behavior.
Expand Down
26 changes: 24 additions & 2 deletions src/webview2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ impl InnerWebView {
.map(|id| id.to_string())
.unwrap_or_else(|| (hwnd.0 as isize).to_string());

let background_color = if attributes.transparent {
Some((0, 0, 0, 0))
} else {
attributes.background_color
};

let env = Self::create_environment(&attributes, pl_attrs.clone())?;
let controller = Self::create_controller(hwnd, &env, attributes.incognito)?;
let controller = Self::create_controller(hwnd, &env, attributes.incognito, background_color)?;
let webview = Self::init_webview(
parent,
hwnd,
Expand Down Expand Up @@ -284,7 +290,7 @@ impl InnerWebView {
// remove "mini menu" - See https://github.com/tauri-apps/wry/issues/535
// and "smart screen" - See https://github.com/tauri-apps/tauri/issues/1345
// enable white flicker fix
let default_args = "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection --enable-features=RemoveRedirectionBitmap";
let default_args = "--disable-features=msWebOOUI,msPdfOOUI,msSmartScreenProtection";
let mut arguments = String::from(default_args);

if attributes.autoplay {
Expand Down Expand Up @@ -355,6 +361,7 @@ impl InnerWebView {
hwnd: HWND,
env: &ICoreWebView2Environment,
incognito: bool,
background_color: Option<(u8, u8, u8, u8)>,
) -> Result<ICoreWebView2Controller> {
let (tx, rx) = mpsc::channel();
let env = env.clone();
Expand All @@ -374,6 +381,21 @@ impl InnerWebView {
unsafe {
if let Ok(env10) = env10 {
let controller_opts = env10.CreateCoreWebView2ControllerOptions()?;

if let Some((r, g, b, mut a)) = background_color {
if let Ok(opts3) = controller_opts.cast::<ICoreWebView2ControllerOptions3>() {
if a != 0 {
a = 255;
}
opts3.SetDefaultBackgroundColor(COREWEBVIEW2_COLOR {
R: r,
G: g,
B: b,
A: a,
})?;
}
}

controller_opts.SetIsInPrivateModeEnabled(incognito)?;
env10.CreateCoreWebView2ControllerWithOptions(hwnd, &controller_opts, &handler)?;
} else {
Expand Down