gui: plugin pages load on Windows again, their sandboxed frame kept in the window's process (Mute06162 on X)
Mute06162 on X (0.1.4066, Windows): every plugin page (用量速览, 对话,
模型指纹, GPT号池) showed "This page stopped working / <page> didn't
answer", and Codex found "Worker request cancellation setup: The
parameter is incorrect" and "Resuming Windows asset request: The
parameter is incorrect" in the log. Both are Wails' own lines
(request_cancellation_windows.go, v3.0.0-beta.24).
Cause, reproduced on xiaomi-gpu (WebView2 157.0.4341.46): WebView2 runs
the plugin page's frame (sandbox="allow-scripts") in a process of its
own (Chromium's IsolateSandboxedIframes; CDP lists it as an "iframe"
target). Wails registers its WebResourceRequested filter with
AddWebResourceRequestedFilter, and that isn't raised for this process's
requests: the frame got its index.html (a navigation), but bridge.js,
app.js and style.css went to the network as http://wails.localhost/...
and failed with net::ERR_CONNECTION_REFUSED. The bridge never said
hello, so after 10s the page was broken. Wails' request cancellation
auto-attaches the frame's target, takes it for a worker, and its setup
on that session fails with E_INVALIDARG: that is the log line.
Fix: windowsOptions starts WebView2 with IsolateSandboxedIframes
disabled (sharedFrameProcess), merged into the one --disable-features
with the user's own, unless the user enables it in
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS. This is app-wide, so it covers
every sandboxed frame magpie makes: plugin pages and plugin panels
(pluginpages.js, the only two), in the main window and the tray panel.
The frame keeps its sandbox: an opaque origin (its context's origin is
"://"), its CSP, messages only.
Run:
- Real repro on xiaomi-gpu, sandbox HOME (C:\Users\yeton\magpie-wvf),
testdata/page-plugin (magpie-usage-glance, the reporter's 用量速览),
`magpie app` started in the console session by a one-shot scheduled
task, driven over CDP:
- origin/main 077421733: the page shows "This page stopped working /
Usage glance 的页面没有响应"; the frame target's three subresources
fail ERR_CONNECTION_REFUSED; err.log has "Worker request
cancellation setup: The parameter is incorrect." on every open.
- origin/main with --disable-features=IsolateSandboxedIframes set by
hand in WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS: the frame stays.
- this change: the card draws (screenshot: "Today, 0 calls, 0 tokens,
$0.00, Hide cost", so the bridge and usage:summary read work), and
no Wails line is logged.
- TestWebView2KeepsPluginFramesInTheWindowProcess (new): win-run
`go test -run WebView2 ./internal/gui` ok on xiaomi-gpu. Broken by
hand (sharedFrameProcess not called): red on Windows, "disabled 0
times". TestWebView2ArgsMergeTheUsers and
TestWebView2ArgsSurviveWailsInit updated for the new default.
- mote: go test ./internal/gui ok (158s).
- mica: go vet ./internal/gui for GOOS=windows, GOOS=linux -tags nogui
and darwin ok; gofmt -l clean.
Not tried: an older WebView2 runtime (when the runtime turned the
isolation on is not proven; 157 has it), the reporter's other three
plugins (they are frames like this one), Wails' own fix (registering the
filter for every request source kind), and the whole internal/gui
package on Windows.
This commit is contained in:
@@ -351,6 +351,18 @@ starts a Bun host.
|
||||
images and fonts the page loads itself. index.html's manifest link asks
|
||||
with `crossorigin="use-credentials"`. `TestPluginPageWebComesAsOneDocument`,
|
||||
`plugin-page-cookie-proxy.test.cjs`.
|
||||
- **The frame's process on Windows.** WebView2 157 runs a sandboxed frame
|
||||
in a process of its own (Chromium's `IsolateSandboxedIframes`), and
|
||||
Wails' `WebResourceRequested` filter isn't raised for that process's
|
||||
requests: a page got its index.html, but its bridge.js, scripts and
|
||||
stylesheet went to the network as `http://wails.localhost/...` and were
|
||||
refused, so every page and panel said it didn't answer (Mute06162 on X,
|
||||
0.1.4066). Wails' request cancellation also logged "Worker request
|
||||
cancellation setup: The parameter is incorrect" for the frame.
|
||||
`windowsOptions` starts WebView2 with the feature disabled
|
||||
(`sharedFrameProcess`), unless the user enables it in
|
||||
`WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS`; the frame keeps its sandbox and
|
||||
opaque origin. `TestWebView2KeepsPluginFramesInTheWindowProcess`.
|
||||
- **Slots.** A page names a slot with `<div class="plugin-slot"
|
||||
data-slot="…" hidden>` in its markup, or app.js draws one with
|
||||
`magpie.slot(name, context)` ([`pluginpages.js`](../../internal/gui/assets/pluginpages.js)).
|
||||
|
||||
+3
-1
@@ -315,10 +315,12 @@ func (h *host) zoomWindows() {
|
||||
// a folder a portable magpie must not leave behind (#508). Installed, it
|
||||
// stays there, so what the pages kept isn't lost. The browser arguments
|
||||
// the user set in WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS, which Wails' loader
|
||||
// blanks before WebView2 can read them, are merged into Wails' own (#2753).
|
||||
// blanks before WebView2 can read them, are merged into Wails' own (#2753),
|
||||
// after magpie's own (sharedFrameProcess).
|
||||
// Display changes are read with a callback made once (screens_windows.go).
|
||||
func windowsOptions() application.WindowsOptions {
|
||||
disabled, enabled, other := webView2Args(webview2env.Args)
|
||||
disabled = sharedFrameProcess(disabled, enabled)
|
||||
return application.WindowsOptions{
|
||||
DisableQuitOnLastWindowClosed: true,
|
||||
WebviewUserDataPath: appdir.WebView(),
|
||||
|
||||
@@ -95,6 +95,31 @@ func webView2Args(env string) (disabled, enabled, other []string) {
|
||||
return disabled, enabled, other
|
||||
}
|
||||
|
||||
// isolateSandboxedFrames is the Chromium feature that runs a sandboxed
|
||||
// frame in a process of its own. WebView2 157 has it on, and Wails
|
||||
// (v3.0.0-beta.24) registers its WebResourceRequested filter with
|
||||
// AddWebResourceRequestedFilter, which isn't raised for the requests
|
||||
// such a frame makes: a plugin's page or panel (pluginpages.js, sandbox
|
||||
// allow-scripts) got its index.html, but its bridge.js, scripts and
|
||||
// stylesheet went out to the network as http://wails.localhost/... and
|
||||
// failed with ERR_CONNECTION_REFUSED, so the page never said hello and
|
||||
// showed "This page stopped working" (Mute06162 on X, 0.1.4066). Wails'
|
||||
// request cancellation took the frame for a worker too, and logged
|
||||
// "Worker request cancellation setup: The parameter is incorrect."
|
||||
const isolateSandboxedFrames = "IsolateSandboxedIframes"
|
||||
|
||||
// sharedFrameProcess is disabled with isolateSandboxedFrames first, so a
|
||||
// sandboxed frame stays in its window's process, where Wails serves its
|
||||
// requests. The frame keeps its sandbox: an opaque origin, its own policy
|
||||
// (pagePolicy), no way to the window but messages. A user who enables
|
||||
// the feature in WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS keeps it on.
|
||||
func sharedFrameProcess(disabled, enabled []string) []string {
|
||||
if slices.Contains(enabled, isolateSandboxedFrames) {
|
||||
return disabled
|
||||
}
|
||||
return addFeatures([]string{isolateSandboxedFrames}, strings.Join(disabled, ","))
|
||||
}
|
||||
|
||||
// addFeatures adds a comma list's features to have, each once.
|
||||
func addFeatures(have []string, list string) []string {
|
||||
for _, f := range strings.Split(strings.Trim(list, `"`), ",") {
|
||||
|
||||
@@ -43,14 +43,14 @@ func TestWebView2ArgsMergeTheUsers(t *testing.T) {
|
||||
name, env string
|
||||
want []string
|
||||
}{
|
||||
{"none set", "", []string{"--disable-features=msSmartScreenProtection"}},
|
||||
{"none set", "", []string{"--disable-features=msSmartScreenProtection,IsolateSandboxedIframes"}},
|
||||
{"the reporter's", "--disable-features=RendererCodeIntegrity",
|
||||
[]string{"--disable-features=msSmartScreenProtection,RendererCodeIntegrity"}},
|
||||
[]string{"--disable-features=msSmartScreenProtection,IsolateSandboxedIframes,RendererCodeIntegrity"}},
|
||||
{"twice, with magpie's own and a repeat", `--disable-features=A,msSmartScreenProtection --disable-features="B, A"`,
|
||||
[]string{"--disable-features=msSmartScreenProtection,A,B"}},
|
||||
[]string{"--disable-features=msSmartScreenProtection,IsolateSandboxedIframes,A,B"}},
|
||||
{"enable and others kept", " --enable-features=X,Y\t--remote-debugging-port=9333 --proxy-server=\"http://h:1 x\" --enable-features=Y,Z --lang=de ",
|
||||
[]string{"--disable-features=msSmartScreenProtection", "--enable-features=X,Y,Z", "--remote-debugging-port=9333", `--proxy-server="http://h:1 x"`, "--lang=de"}},
|
||||
{"a bare switch", "--disable-features", []string{"--disable-features=msSmartScreenProtection"}},
|
||||
[]string{"--disable-features=msSmartScreenProtection,IsolateSandboxedIframes", "--enable-features=X,Y,Z", "--remote-debugging-port=9333", `--proxy-server="http://h:1 x"`, "--lang=de"}},
|
||||
{"a bare switch", "--disable-features", []string{"--disable-features=msSmartScreenProtection,IsolateSandboxedIframes"}},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
was := webview2env.Args
|
||||
@@ -73,6 +73,59 @@ func TestWebView2ArgsMergeTheUsers(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// Mute06162 on X (0.1.4066, Windows): every plugin page said "This page
|
||||
// stopped working". WebView2 157 runs a sandboxed frame in a process of
|
||||
// its own, and Wails' WebResourceRequested isn't raised for that
|
||||
// process's requests, so the page's bridge.js and scripts were refused
|
||||
// (ERR_CONNECTION_REFUSED) and it never said hello. magpie's WebView2
|
||||
// starts with the frame isolation off, beside the user's own features
|
||||
// and once only; a user who turns it on keeps it.
|
||||
func TestWebView2KeepsPluginFramesInTheWindowProcess(t *testing.T) {
|
||||
was := webview2env.Args
|
||||
t.Cleanup(func() { webview2env.Args = was })
|
||||
for _, c := range []struct {
|
||||
name, env, keep string // keep: the user's own, still in the arguments
|
||||
off, enabled bool
|
||||
}{
|
||||
{"default", "", "", true, false},
|
||||
{"the user's own features", "--disable-features=RendererCodeIntegrity --lang=de", "RendererCodeIntegrity", true, false},
|
||||
{"the user disables it too", "--disable-features=IsolateSandboxedIframes,A", ",A", true, false},
|
||||
{"the user turns it on", "--enable-features=IsolateSandboxedIframes", "", false, true},
|
||||
} {
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
webview2env.Args = c.env
|
||||
args := wailsBrowserArgs(windowsOptions())
|
||||
var off, on int
|
||||
for _, a := range args {
|
||||
k, v, _ := strings.Cut(a, "=")
|
||||
for _, f := range strings.Split(v, ",") {
|
||||
if f != "IsolateSandboxedIframes" {
|
||||
continue
|
||||
}
|
||||
switch k {
|
||||
case "--disable-features":
|
||||
off++
|
||||
case "--enable-features":
|
||||
on++
|
||||
}
|
||||
}
|
||||
}
|
||||
if c.off && off != 1 {
|
||||
t.Fatalf("IsolateSandboxedIframes disabled %d times in %q, want once: a plugin's sandboxed frame gets a process whose requests Wails doesn't serve", off, args)
|
||||
}
|
||||
if !c.off && off != 0 {
|
||||
t.Fatalf("the user's IsolateSandboxedIframes is disabled: %q", args)
|
||||
}
|
||||
if c.enabled != (on == 1) {
|
||||
t.Fatalf("enabled %d times in %q", on, args)
|
||||
}
|
||||
if !strings.Contains(strings.Join(args, " "), c.keep) {
|
||||
t.Fatalf("the user's %s is lost: %q", c.keep, args)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Nothing in the defaults turns renderer code integrity off: only a user
|
||||
// who asks for it gets it (#2753).
|
||||
func TestWebView2KeepsCodeIntegrityByDefault(t *testing.T) {
|
||||
@@ -104,7 +157,7 @@ func TestWebView2ArgsSurviveWailsInit(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatalf("child: %v\n%s", err, out)
|
||||
}
|
||||
if !strings.Contains(string(out), `disabled=["RendererCodeIntegrity"]`) {
|
||||
if !strings.Contains(string(out), `disabled=["IsolateSandboxedIframes" "RendererCodeIntegrity"]`) {
|
||||
t.Fatalf("the started value didn't reach the options:\n%s", out)
|
||||
}
|
||||
t.Logf("%s", strings.SplitN(string(out), "\n", 2)[0])
|
||||
|
||||
Reference in New Issue
Block a user