Fix browser WebView refresh on workspace hide

Merged
AU
6mo ago
+173-66

Summary

  • make Browser Memory Saver opt-in so normal workspace hide/show keeps the live WKWebView and DOM state
  • add a regression test for hiding past the discard delay without replacing the WKWebView
  • keep explicit memory-saver discard coverage by enabling the policy inside those tests

Fixes #4387

Verification

  • Not run locally per task instruction; CI will run the checks.

[!NOTE]
Medium Risk
Changes the default browser tab lifecycle behavior by disabling hidden WebView discarding unless explicitly enabled, which could affect memory usage and tab restore behavior. Risk is mitigated by updated and new unit tests around discard/restore and workspace hide/show identity preservation.

Overview
Makes Browser Memory Saver opt-in by changing BrowserHiddenWebViewDiscardPolicy.defaultEnabled and the settings schema browser.discardHiddenWebViews default from true to false, so normal workspace hide/show keeps the same live WKWebView and DOM state.

Updates BrowserPanelWebViewLifecycleTests to manage discard-related UserDefaults per-test, skip appropriately when environment overrides make behavior unobservable, add a regression test asserting WebView identity is preserved when hidden past the discard delay with the policy disabled, and explicitly enable the policy in discard/restore tests to keep coverage.

Reviewed by Cursor Bugbot for commit 233dbe4b515d381e6dd7412e6553be9e34138429. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Make Browser Memory Saver opt-in so hidden tabs no longer auto-discard. Keeps the live WKWebView and DOM when a workspace is hidden and re-shown, fixing the refresh regression (addresses #4387).

  • Bug Fixes
    • Default BrowserHiddenWebViewDiscardPolicy to disabled; update discardHiddenWebViews default in web/data/cmux.schema.json to false.
    • Preserve WKWebView identity across workspace hide/show to avoid reloads.
    • Add regression tests for the default-preserve behavior and for explicit memory-saver discard paths (with environment override handling).