Skip to content

Commit

Permalink
[v2, webview2loader] Prevent env and registry overrides when using th…
Browse files Browse the repository at this point in the history
…e go loader (#2668)
  • Loading branch information
stffabi authored May 15, 2023
1 parent c1a0e13 commit 22b5319
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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

0 comments on commit 22b5319

Please sign in to comment.