From 22b53192e6ee72f7919790953e29a4589a4d8d76 Mon Sep 17 00:00:00 2001 From: stffabi Date: Mon, 15 May 2023 21:12:16 +0200 Subject: [PATCH] [v2, webview2loader] Prevent env and registry overrides when using the go loader (#2668) --- .../go-webview2/webviewloader/env_create.go | 17 +++++++++++++++++ website/src/pages/changelog.mdx | 4 ++++ 2 files changed, 21 insertions(+) diff --git a/v2/internal/frontend/desktop/windows/go-webview2/webviewloader/env_create.go b/v2/internal/frontend/desktop/windows/go-webview2/webviewloader/env_create.go index 1c586d2c6..892189a4a 100644 --- a/v2/internal/frontend/desktop/windows/go-webview2/webviewloader/env_create.go +++ b/v2/internal/frontend/desktop/windows/go-webview2/webviewloader/env_create.go @@ -4,6 +4,7 @@ package webviewloader import ( "fmt" + "os" "path/filepath" "syscall" "unsafe" @@ -14,6 +15,7 @@ import ( func init() { fmt.Println("DEB | Using go webview2loader") + preventEnvAndRegistryOverrides() } type webView2RunTimeType int32 @@ -104,6 +106,8 @@ func createWebViewEnvironmentWithClientDll(lpLibFileName string, runtimeType web envCompletedCom := combridge.New[iCoreWebView2CreateCoreWebView2EnvironmentCompletedHandler](envCompletedHandler) defer envCompletedCom.Close() + preventEnvAndRegistryOverrides() + const unknown = 1 hr, _, err := createProc.Call( uintptr(unknown), @@ -157,3 +161,16 @@ func (r *environmentCreatedHandler) EnvironmentCompleted(errorCode HRESULT, crea return HRESULT(windows.S_OK) } + +func preventEnvAndRegistryOverrides() { + // Setting these env variables to empty string also prevents registry overrides because webview2 + // checks for existence and not for empty value + os.Setenv("WEBVIEW2_PIPE_FOR_SCRIPT_DEBUGGER", "") + os.Setenv("WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS", "") + os.Setenv("WEBVIEW2_RELEASE_CHANNEL_PREFERENCE", "0") + + // The following seems not be be required because those are only used by the webview2loader which + // in this case is implemented on our own. But nevertheless set them to empty to be consistent. + os.Setenv("WEBVIEW2_BROWSER_EXECUTABLE_FOLDER", "") + os.Setenv("WEBVIEW2_USER_DATA_FOLDER", "") +} diff --git a/website/src/pages/changelog.mdx b/website/src/pages/changelog.mdx index d234723c2..5933b4556 100644 --- a/website/src/pages/changelog.mdx +++ b/website/src/pages/changelog.mdx @@ -14,6 +14,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Breaking Changes + +- The Go WebView2Loader allowed env variable and registry overrides to change the behaviour of WebView2. This is not possible when using the native WebView2Loader with Wails and should not be possible according to [PR](https://github.com/wailsapp/wails/pull/1771). Changed by @stffabi in [PR](https://github.com/wailsapp/wails/pull/2668) + ## v2.5.0 - 2023-05-13 ### Breaking Changes