diff --git a/docs/subsystems/plugin-runtime.md b/docs/subsystems/plugin-runtime.md
index 37ad92af5..5b07679c5 100644
--- a/docs/subsystems/plugin-runtime.md
+++ b/docs/subsystems/plugin-runtime.md
@@ -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 `
` in its markup, or app.js draws one with
`magpie.slot(name, context)` ([`pluginpages.js`](../../internal/gui/assets/pluginpages.js)).
diff --git a/internal/gui/app.go b/internal/gui/app.go
index 441a2babe..1c19884bc 100644
--- a/internal/gui/app.go
+++ b/internal/gui/app.go
@@ -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(),
diff --git a/internal/gui/webview2.go b/internal/gui/webview2.go
index 832214849..148671149 100644
--- a/internal/gui/webview2.go
+++ b/internal/gui/webview2.go
@@ -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, `"`), ",") {
diff --git a/internal/gui/webview2_args_test.go b/internal/gui/webview2_args_test.go
index b7382bbb6..d9a935c07 100644
--- a/internal/gui/webview2_args_test.go
+++ b/internal/gui/webview2_args_test.go
@@ -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])