Files
magpie/internal/gui/webviewmend.go
T
yetone f46a37f509 gui: a WebView2 process that fails is logged and the window comes back by itself
aquaarboraurum on X (magpie 0.1.4040, Windows 11, WebView2 138): the
main window went white after a while, leaving the title bar, a strip at
the left edge and the status bar. Closing it to the tray and opening it
again brought it back, and the log said nothing.

Wails registers for WebView2's ProcessFailed but leaves its
ProcessFailedCallback unset, so nothing in magpie heard any WebView2
process end or fail. Now each window's failures are handled, once its
first page has come (webviewmend*.go):

- each one is logged: "webview (main window): GPU process exited;
  drawing it again", and so on for every COREWEBVIEW2_PROCESS_FAILED_KIND;
- GPU, unknown or a new kind: the controller is hidden and shown again
  (put_IsVisible), what the tray close and open did, without the window
  going;
- a render process that exits or hangs, or a frame's: the page is
  reloaded (ICoreWebView2::Reload);
- the browser process: the window is let go as lightweight mode does and
  the main window made again, once the old browser has let go of the
  profile folder (made at once, Wails ended magpie on a controller
  timeout);
- utility, sandbox helper and plugin processes: logged only;
- a reload or remake again within 30s is logged and left alone, so a
  failing renderer doesn't loop;
- after the computer wakes (SystemDidWake), each open window is drawn
  again the same way, since a GPU that lost its device while asleep is
  the likeliest way to a white surface with the window's frame left.

The cause of the report is not proven. Ending the GPU process on the
Windows box doesn't leave the old code white (WebView2 makes a new one
and the page keeps drawing), and a dead renderer doesn't match a window
that the tray brings back. The log line is what the next report needs.

Run:
- TestWebViewComesBackFromEachProcessEnd (new) on xiaomi-gpu, Windows 11
  25H2, WebView2 157, in the signed-in session (schtasks /it; it skips
  over ssh, session 0): it ends the test build's own renderer, GPU
  process and browser process and checks the page comes back drawn
  (screen pixels over the client area, white share 0.00) - renderer,
  gpu-process and browser all PASS (16.4s).
- Broken by hand (mendWebView taken out of makeMain): all three red -
  "the page didn't load", "hidden=false, never visible again", "timed
  out waiting until the window is made again".
- Old code, GPU process ended, white share sampled 10s: 0.00 every second
  (not white: the cause above is not reproduced).
- TestWebViewMendForEachFailure, TestMendGapHoldsOnlyReloadAndRemake.
- mica: go vet ./internal/gui (darwin, GOOS=windows), go vet -tags nogui
  (darwin, linux, windows), go test -count=1 ./internal/gui ok 137s.
- mica, go test -count=1 -timeout 45m ./... at f9ad4122b plus this
  change: 98 packages ok, one red, TestNoEagerPackageRegexps on
  davsync's setuptext.go (#6534, red on main, fixed in the next commit).
- xiaomi-gpu, go test ./internal/gui over ssh: 9 reds, the same 9 at
  origin/main f9ad4122b run the same way (#6068, #6059, #5928): %AppData%
  unset over ssh, file locks, Smart App Control; none touch WebView2.

Not tried: a real GPU device loss after sleep or display off, the
reporter's WebView2 138, the panel's remake (the same code path as
lightweight mode's let-go).
2026-11-13 19:45:24 +08:00

98 lines
3.4 KiB
Go

package gui
import (
"fmt"
"time"
)
// A WebView2 whose process fails was left as it fell: nothing in Wails
// handles ProcessFailed, and nothing was logged. aquaarboraurum on X
// (0.1.4040, Windows 11, WebView2 138): after a while the main window went
// white but for its title bar, a sliver at the left edge and the status
// bar, with nothing in the log, and closing it to the tray and opening it
// again brought it back. Closing and opening hides the WebView2 controller
// and shows it again, which has it draw its surface anew. magpie now does
// what each failure needs (webViewMendFor) and logs it.
// webViewMend is what magpie does for a failed WebView2 process.
type webViewMend int
const (
mendNothing webViewMend = iota
// mendRedraw hides the controller and shows it again: what the tray's
// close and open did by hand. WebView2 starts a GPU process again by
// itself, but a window that stays shown may keep the surface the old
// one drew, white.
mendRedraw
// mendReload reloads the page: a renderer that ended is replaced with
// an error page, one that hangs draws nothing more.
mendReload
// mendRemake makes the window again: a browser process that ended
// closes its webviews for good.
mendRemake
)
// COREWEBVIEW2_PROCESS_FAILED_KIND's values (WebView2.h).
const (
wv2BrowserExited = 0
wv2RenderExited = 1
wv2RenderUnresponsive = 2
wv2FrameRenderExited = 3
wv2UtilityExited = 4
wv2SandboxHelperExited = 5
wv2GPUExited = 6
wv2PPAPIPluginExited = 7
wv2PPAPIBrokerExited = 8
wv2UnknownExited = 9
)
// webViewMendFor names a ProcessFailed kind and says what is done for it.
// A process whose end leaves the page as it was (a utility process, a
// sandbox helper, a plugin) needs nothing; an unknown one gets a redraw,
// which costs nothing and is what brought the white window back.
func webViewMendFor(kind uint32) (string, webViewMend) {
switch kind {
case wv2BrowserExited:
return "browser process exited", mendRemake
case wv2RenderExited:
return "render process exited", mendReload
case wv2RenderUnresponsive:
return "render process unresponsive", mendReload
case wv2FrameRenderExited:
return "a frame's render process exited", mendReload
case wv2UtilityExited:
return "utility process exited", mendNothing
case wv2SandboxHelperExited:
return "sandbox helper process exited", mendNothing
case wv2GPUExited:
return "GPU process exited", mendRedraw
case wv2PPAPIPluginExited, wv2PPAPIBrokerExited:
return "plugin process exited", mendNothing
case wv2UnknownExited:
return "a process exited", mendRedraw
}
return fmt.Sprintf("process failed (kind %d)", kind), mendRedraw
}
// mendGap is how soon after a reload or a remake of a window another is
// not made: a page that brings its renderer down again as it loads would
// otherwise be reloaded without end. The failure is still logged.
const mendGap = 30 * time.Second
// mendAllowed says whether a mend may run at now, the last heavy one
// (reload or remake) having run at last (zero: never). A redraw always may.
func mendAllowed(m webViewMend, last, now time.Time) bool {
if m != mendReload && m != mendRemake {
return true
}
return last.IsZero() || now.Sub(last) >= mendGap
}
// mendWords say each mend in the log.
var mendWords = map[webViewMend]string{
mendNothing: "nothing to do",
mendRedraw: "drawing it again",
mendReload: "reloading the page",
mendRemake: "making the window again",
}