From 4c70d4501e4f77147a3915ddbfc972b8881b0c69 Mon Sep 17 00:00:00 2001 From: Hudolus Date: Sat, 2 Aug 2025 06:03:41 -0500 Subject: [PATCH] Custom Windows Webview2 Args (#4467) * Adding the ability to pass custom args to windows webview2 --------- Co-authored-by: Jason Gibson Co-authored-by: Lea Anthony --- v3/UNRELEASED_CHANGELOG.md | 4 +++- v3/pkg/application/webview_window_options.go | 8 +++++--- v3/pkg/application/webview_window_windows.go | 4 ++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/v3/UNRELEASED_CHANGELOG.md b/v3/UNRELEASED_CHANGELOG.md index 4f5e6feca..f0c37fb04 100644 --- a/v3/UNRELEASED_CHANGELOG.md +++ b/v3/UNRELEASED_CHANGELOG.md @@ -15,7 +15,9 @@ This file is automatically processed by the nightly release workflow. After processing, the content will be moved to the main changelog and this file will be reset. --> -### Added +## Added + +- Added `AdditionalLaunchArgs` to `WindowsWindow` options to allow for additional command line arguments to be passed to the WebView2 browser. in [PR](https://github.com/wailsapp/wails/pull/4467) - Added Run go mod tidy automatically after wails init [@triadmoko](https://github.com/triadmoko) in [PR](https://github.com/wailsapp/wails/pull/4286) - Windows Snapassist feature by @leaanthony in [PR](https://github.dev/wailsapp/wails/pull/4463) diff --git a/v3/pkg/application/webview_window_options.go b/v3/pkg/application/webview_window_options.go index e37de2f09..123c60069 100644 --- a/v3/pkg/application/webview_window_options.go +++ b/v3/pkg/application/webview_window_options.go @@ -292,13 +292,15 @@ type WindowsWindow struct { // PasswordAutosaveEnabled enables autosaving passwords PasswordAutosaveEnabled bool - // EnabledFeatures and DisabledFeatures are used to enable or disable specific features in the WebView2 browser. + // EnabledFeatures, DisabledFeatures and AdditionalLaunchArgs are used to enable or disable specific features in the WebView2 browser. // Available flags: https://learn.microsoft.com/en-us/microsoft-edge/webview2/concepts/webview-features-flags?tabs=dotnetcsharp#available-webview2-browser-flags // WARNING: Apps in production shouldn't use WebView2 browser flags, // because these flags might be removed or altered at any time, // and aren't necessarily supported long-term. - EnabledFeatures []string - DisabledFeatures []string + // AdditionalLaunchArgs should always be preceded by "--" + EnabledFeatures []string + DisabledFeatures []string + AdditionalLaunchArgs []string } type Theme int diff --git a/v3/pkg/application/webview_window_windows.go b/v3/pkg/application/webview_window_windows.go index aceb3a88d..4ec5b288c 100644 --- a/v3/pkg/application/webview_window_windows.go +++ b/v3/pkg/application/webview_window_windows.go @@ -1798,6 +1798,10 @@ func (w *windowsWebviewWindow) setupChromium() { chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, arg) } + if len(opts.AdditionalLaunchArgs) > 0 { + chromium.AdditionalBrowserArgs = append(chromium.AdditionalBrowserArgs, opts.AdditionalLaunchArgs...) + } + chromium.DataPath = globalApplication.options.Windows.WebviewUserDataPath chromium.BrowserPath = globalApplication.options.Windows.WebviewBrowserPath