mirror of
https://wget.la/https://github.com/leookun/cursor-byok
synced 2026-08-18 03:57:06 +08:00
fix: gate WebView sandbox opt-out behind environment variable
This commit is contained in:
+13
-3
@@ -8,7 +8,9 @@ import (
|
|||||||
"encoding/pem"
|
"encoding/pem"
|
||||||
"io/fs"
|
"io/fs"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
goruntime "runtime"
|
goruntime "runtime"
|
||||||
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -37,6 +39,8 @@ const (
|
|||||||
appName = "Cursor助手"
|
appName = "Cursor助手"
|
||||||
// adRefreshInterval 表示后台广告拉取间隔。
|
// adRefreshInterval 表示后台广告拉取间隔。
|
||||||
adRefreshInterval = 3 * time.Minute
|
adRefreshInterval = 3 * time.Minute
|
||||||
|
// disableWebViewSandboxEnv allows affected VDI users to opt out of the WebView2 sandbox.
|
||||||
|
disableWebViewSandboxEnv = "CURSOR_BYOK_DISABLE_WEBVIEW_SANDBOX"
|
||||||
)
|
)
|
||||||
|
|
||||||
// EmbeddedResources 定义了当前模块中的 EmbeddedResources 类型。
|
// EmbeddedResources 定义了当前模块中的 EmbeddedResources 类型。
|
||||||
@@ -135,9 +139,7 @@ func Run(resources EmbeddedResources) error {
|
|||||||
Handler: application.AssetFileServerFS(resources.Assets),
|
Handler: application.AssetFileServerFS(resources.Assets),
|
||||||
},
|
},
|
||||||
Windows: application.WindowsOptions{
|
Windows: application.WindowsOptions{
|
||||||
// VDI 环境(如 VMware Horizon)会阻止 WebView2 创建沙箱受限令牌的renderer 进程,导致主窗口白屏。
|
AdditionalBrowserArgs: windowsAdditionalBrowserArgs(),
|
||||||
// --no-sandbox 跳过受限沙箱创建,使渲染进程可以正常启动。
|
|
||||||
AdditionalBrowserArgs: []string{"--no-sandbox"},
|
|
||||||
},
|
},
|
||||||
Mac: application.MacOptions{
|
Mac: application.MacOptions{
|
||||||
ActivationPolicy: application.ActivationPolicyAccessory,
|
ActivationPolicy: application.ActivationPolicyAccessory,
|
||||||
@@ -420,6 +422,14 @@ func Run(resources EmbeddedResources) error {
|
|||||||
return app.Run()
|
return app.Run()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func windowsAdditionalBrowserArgs() []string {
|
||||||
|
disableSandbox, err := strconv.ParseBool(strings.TrimSpace(os.Getenv(disableWebViewSandboxEnv)))
|
||||||
|
if err != nil || !disableSandbox {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return []string{"--no-sandbox"}
|
||||||
|
}
|
||||||
|
|
||||||
func browserReachableLoopbackBaseURL(listenAddr string) string {
|
func browserReachableLoopbackBaseURL(listenAddr string) string {
|
||||||
host, port, err := net.SplitHostPort(strings.TrimSpace(listenAddr))
|
host, port, err := net.SplitHostPort(strings.TrimSpace(listenAddr))
|
||||||
if err != nil || strings.TrimSpace(port) == "" {
|
if err != nil || strings.TrimSpace(port) == "" {
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package app
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWindowsAdditionalBrowserArgs(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
env string
|
||||||
|
want []string
|
||||||
|
}{
|
||||||
|
{name: "unset"},
|
||||||
|
{name: "enabled with one", env: "1", want: []string{"--no-sandbox"}},
|
||||||
|
{name: "enabled with true", env: " true ", want: []string{"--no-sandbox"}},
|
||||||
|
{name: "disabled", env: "false"},
|
||||||
|
{name: "invalid", env: "yes"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
t.Setenv(disableWebViewSandboxEnv, tt.env)
|
||||||
|
if got := windowsAdditionalBrowserArgs(); !reflect.DeepEqual(got, tt.want) {
|
||||||
|
t.Fatalf("windowsAdditionalBrowserArgs() = %v, want %v", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user