Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v2 webviewloader] Prevent env and registry overrides when using the go loader #2668

Merged
merged 1 commit into from
May 15, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package webviewloader

import (
"fmt"
"os"
"path/filepath"
"syscall"
"unsafe"
Expand All @@ -14,6 +15,7 @@ import (

func init() {
fmt.Println("DEB | Using go webview2loader")
preventEnvAndRegistryOverrides()
}

type webView2RunTimeType int32
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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", "")
}
4 changes: 4 additions & 0 deletions website/src/pages/changelog.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down