Commit Graph
3 Commits
Author SHA1 Message Date
yetone ce2ce86ab4 gui: windows drawn again when the screen comes back, WebView2 without occlusion tracking (aquaarboraurum on X)
aquaarboraurum: on Windows the window that comes back after every
auto-update restart is white. Its title bar and status bar are there,
and its page is alive. A restart by hand or a reload draws it.

AutoRestart only restarts once nothing is going through magpie and the
window has sat unused, which is when the user is away, often with the
screen locked or the display off. A WebView2 window first shown then
can keep a white surface: Chromium's native occlusion tracking takes
every window as covered while the screen is locked, and a surface first
drawn in that state may not be drawn again. Closing the window to the
tray and opening it again, which the reporter did by hand, draws it.

- windowsOptions starts WebView2 with CalculateNativeWinOcclusion
  disabled (occlusionOff), after the user's own features. A user who
  enables it in WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS keeps it on.
  Wails still tells a hidden or minimised window so (put_IsVisible).
- Wails' main-thread window registers for session and display-state
  notifications (watchScreenBack). The app's WndProcInterceptor
  (appWndProc, which still calls screensWndProc) draws each open window
  again (redrawShown) when the session is unlocked or the display comes
  on after being off, as mendOnWake already did on wake.

Not reproduced: the white window never showed on xiaomi-gpu (Windows
11, WebView2 157.0.4341.46). The tries:
- quiet and asked restarts, behind other windows, maximised, under a
  full-screen cover, cloaked, minimised then restored;
- the real sandboxed AutoRestart update path (v0.1.9000 to v0.1.9001
  from a local feed).
The box's screen can't be locked for a test, so the locked-screen case
the fix is aimed at wasn't tried.

Run:
- Windows (xiaomi-gpu, signed-in session):
  - TestRestartedWindowIsDrawn: all 13 modes pass on the fix. The test
    is new and plays the update restart (old process, markQuietRestart,
    AwaitPredecessor, openMain). Each mode now also posts an unlock to
    the app's own main-thread window, checks that the window is drawn
    again and stays drawn, and checks that the msedgewebview2 browser's
    command line has CalculateNativeWinOcclusion disabled.
  - Broken by hand (the interceptor ignoring the unlock, occlusionOff
    returning the list unchanged): red on both checks.
  - go vet ./internal/gui; TestScreenBackFrom,
    TestAppWndProcSaysTheScreenIsBack, TestWebView2* pass.
  - The real update path with exes built from this tree: the new
    process's window came up drawn (10 of 360 sampled points white,
    the same as the old window) over 22s of samples.
- mote:
  - gofmt -l;
  - go vet ./internal/gui/..., GOOS=linux -tags nogui, GOOS=windows;
  - GOOS=windows go build ./..., GOOS=linux go build -tags nogui ./...;
  - go test ./internal/gui (142s) and -tags nogui (95s): ok.

Not run: the full ./... suite. mote and mica were both over their load
(mote's suite.lock had four suites queued). The change is in
internal/gui only.
2026-11-13 23:36:49 +08:00
yetone 6e03b746be 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.
2026-11-13 23:17:31 +08:00
yetone 3608ed782e gui: WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS reaches magpie's WebView2 on Windows again (#2753, LuYquan)
The reporter's Nahimic DLL gets WebView2's renderer killed by code
integrity and the window goes black; the usual workaround,
WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--disable-features=RendererCodeIntegrity,
never reached magpie's renderer. The cause is not WebView2 skipping the
variable because magpie passes its own arguments: Wails v3.0.0-beta.24's
loader blanks the variable in its package init
(webviewloader.preventEnvAndRegistryOverrides), before any magpie code
runs. Seen on the Windows box: a debug build's windowsOptions read "".

- internal/webview2env reads the variable at init. It imports only
  syscall, so by Go's init order (first ready package by import path)
  it is initialized before os, and so before Wails' loader, which needs
  os.
- windowsOptions sorts it into Wails' DisabledFeatures, EnabledFeatures
  and AdditionalBrowserArgs. Wails writes msSmartScreenProtection plus
  the user's features as one --disable-features (Chromium keeps only
  the last of two), one --enable-features, and the rest as written.
  A list given twice is merged, each feature once.
- Nothing is added by default: RendererCodeIntegrity stays on unless
  the user asks.

ProcessFailed: not done. Wails' edge.Chromium has a ProcessFailedCallback,
but setupChromium never sets it, the package is under wails/v3/internal
(not importable) and a window's chromium is unexported; Wails has no
public event for a dead renderer. Reloading on renderer death needs a
change in Wails.

Run:
- gofmt -l: clean. go vet darwin, GOOS=linux -tags nogui, GOOS=windows:
  clean. Builds for the three.
- go test ./internal/gui -run 'TestWebView2|TestWindowsOptions' on
  macOS, and the windows/amd64 test binary on the Windows box (sandbox
  dir, my own process name): TestWebView2ArgsSurviveWailsInit passes
  there with os="" (Wails blanked it) and disabled=[RendererCodeIntegrity].
- The real app on the Windows box (portable sandbox, MAGPIE_ADDR :3481,
  USERPROFILE/APPDATA/LOCALAPPDATA redirected) started with
  "--disable-features=RendererCodeIntegrity --enable-features=msTestFoo
  --lang=de": every msedgewebview2.exe of it carries one
  --disable-features with both features, --enable-features=msTestFoo
  and --lang=de. Before, the same launch showed only
  --disable-features=msSmartScreenProtection and --lang=zh-CN.

Broken by hand:
- windowsOptions reading os.Getenv instead of webview2env.Args: on the
  Windows box TestWebView2ArgsSurviveWailsInit goes red
  (os="" disabled=[]).
- webView2Args ignoring the env (""): TestWebView2ArgsMergeTheUsers red
  in "the reporter's" and "twice".
- --disable-features treated as an other argument: red in three cases,
  including the one-switch count.

Full suite at origin/main 1a3b92688 + this and the #2757/#2755 GUI
commits, go test -timeout 45m ./..., sandbox HOME: gofmt -l clean, vet
darwin/linux(nogui)/windows clean, 57 packages ok. At load 475-548 from
other sessions' suites, agent (#2544, #2723), gateway (#2108, #2191;
TestClaudeAccountsSpentFallBackToCodex #2858), library (#2853), davsync,
provider and plugin (#2869; TestGatewayHookMixedPiPackage and
TestHostOnBunLackingLibsSaysWhich #2865) ran past 45m, and internal/gui
had TestSetAnswersWhileDevinAndProvidersHang red (#1375). Rerun alone:
internal/gui and internal/webview2env ok. An earlier full run at
d783df46c + this alone: 61 ok, the same load reds. No asset changes, so
no GUI run.
2026-10-19 07:23:04 +08:00