Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
0804a92
Add failing regression tests for discarded browser webview restore re…
austinywang Jul 7, 2026
17684f9
Fix browser panes stuck black after a failed discard-restore (#7504)
austinywang Jul 7, 2026
cfe0bb7
Merge remote-tracking branch 'origin/main' into issue-7504-browser-di…
austinywang Jul 7, 2026
07b21c4
Fix remote queued discard restore state
austinywang Jul 7, 2026
1dcab64
Handle discarded restore review edge cases
austinywang Jul 8, 2026
449e8cd
Ignore about:blank commits when tracking discarded-restore recovery
austinywang Jul 8, 2026
40b3647
Merge remote-tracking branch 'origin/main' into issue-7504-browser-di…
austinywang Jul 8, 2026
1e042d2
Refresh Swift file length budget for BrowserNavigationDelegate downlo…
austinywang Jul 8, 2026
e190d94
Mark pure lifecycle formatter helpers nonisolated
austinywang Jul 8, 2026
6394ab3
Fix download and no-URL edge cases in discarded webview restore
austinywang Jul 8, 2026
9f9ad5b
Seed committed flag for adopted prewarmed webviews; move commit predi…
austinywang Jul 8, 2026
64273c9
Merge remote-tracking branch 'origin/main' into issue-7504-browser-di…
austinywang Jul 8, 2026
4d71ea1
Gate blank-shell heal off during pending WebContent crash recovery
austinywang Jul 8, 2026
2f2bef9
Cache the lifecycle-payload ISO8601 formatter
austinywang Jul 8, 2026
d8cfb97
Merge remote-tracking branch 'origin/main' into issue-7504-browser-di…
austinywang Jul 8, 2026
70e89e7
Scope committed-document tracking to each discarded restore attempt
austinywang Jul 8, 2026
7b5b343
ci: keep staged macOS jobs alive when web jobs skip
austinywang Jul 8, 2026
74be6ba
ci: align staged macOS job gates with upstream fix and update guard test
austinywang Jul 8, 2026
2555004
Keep restore-stall detection armed after an about:blank commit
austinywang Jul 8, 2026
6c25969
Let explicit reloads restart pending restores; attribute restore call…
austinywang Jul 8, 2026
09b0dac
Never blank-shell-heal over an explicit user Stop
austinywang Jul 8, 2026
90101c2
Merge remote-tracking branch 'origin/main' into issue-7504-browser-di…
austinywang Jul 8, 2026
8012061
Make explicit Stop sticky for discarded restores; move restore flow t…
austinywang Jul 8, 2026
32ed2aa
Never blank-shell-heal over the browser error page
austinywang Jul 8, 2026
7bb6a31
Merge remote-tracking branch 'origin/main' into issue-7504-browser-di…
austinywang Jul 9, 2026
cb2851c
Add queued remote restore regression test
austinywang Jul 9, 2026
c3667e7
Deduplicate queued remote discard restores
austinywang Jul 9, 2026
7b9eda6
Complete policy-cancelled discard restores
austinywang Jul 9, 2026
2610eff
Handle policy-cancelled browser restores explicitly
austinywang Jul 9, 2026
03ebf17
Keep intent fallback restores retryable
austinywang Jul 9, 2026
2623e8d
Complete insecure HTTP prompt restores
austinywang Jul 9, 2026
8a6307b
Preserve current restore attempts on stale cancels
austinywang Jul 9, 2026
7ba6262
Defer external prompt restore completion
austinywang Jul 9, 2026
6345987
Clear stale restore navigation on stalls
austinywang Jul 9, 2026
620bd08
Tokenize browser restore policy cancels
austinywang Jul 9, 2026
9167d38
Keep insecure HTTP restore prompts retryable
austinywang Jul 9, 2026
daa077b
Avoid browser panel budget growth
austinywang Jul 9, 2026
3042ee2
Preserve restore tokens through policy prompts
austinywang Jul 9, 2026
1acb3b4
Scope restore downloads to attempts
austinywang Jul 9, 2026
bf21072
Merge remote-tracking branch 'origin/main' into issue-7504-browser-di…
austinywang Jul 9, 2026
74d3507
Complete terminal restore handling for nil-target tabs
austinywang Jul 9, 2026
348e3ee
Fix PR comment CI guard regressions
austinywang Jul 9, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/swift-file-length-budget.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@
635 cmuxUITests/RightSidebarChromeHeightUITests.swift
630 Packages/macOS/CmuxSettings/Sources/CmuxSettings/Values/ShortcutWhenClause.swift
623 Packages/macOS/CmuxControlSocket/Sources/CmuxControlSocket/Coordinator/Surface/ControlCommandCoordinator+Surface.swift
620 Sources/Panels/BrowserNavigationDelegate.swift
623 Sources/Panels/BrowserNavigationDelegate.swift
620 cmuxTests/FinderFileDropRegressionTests.swift
618 Sources/SettingsNavigation.swift
617 Packages/iOS/CmuxMobileShell/Tests/CmuxMobileShellTests/MobileShellRenderGridLivenessTests.swift
Expand Down
136 changes: 136 additions & 0 deletions Sources/Panels/BrowserDiscardRestoreHeal.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import Foundation

extension BrowserPanel {
static func webViewLifecycleTimestamp(_ date: Date?) -> Any {
guard let date else { return NSNull() }
let formatter = ISO8601DateFormatter()
formatter.formatOptions = [.withInternetDateTime, .withFractionalSeconds]
return formatter.string(from: date)
}

static func webViewHiddenDurationMilliseconds(
hiddenAt: Date?,
visible: Bool,
now: Date
) -> Any {
guard !visible, let hiddenAt else { return NSNull() }
return max(0, Int((now.timeIntervalSince(hiddenAt) * 1000.0).rounded()))
}

nonisolated static func isAboutBlankURL(_ url: URL?) -> Bool {
guard let url else { return false }
let value = url.absoluteString.trimmingCharacters(in: .whitespacesAndNewlines)
return value.caseInsensitiveCompare("about:blank") == .orderedSame
}

nonisolated static func shouldHealBlankShell(
shouldRenderWebView: Bool,
isClosing: Bool,
hasPendingRemoteNavigation: Bool,
isWebViewLoading: Bool,
isMainFrameProvisionalNavigationActive: Bool,
hasCommittedDocument: Bool,
isNavigationBlockedPendingConsent: Bool,
intentURL: URL?
) -> Bool {
guard shouldRenderWebView else { return false }
guard !isClosing else { return false }
guard !hasPendingRemoteNavigation else { return false }
guard !isWebViewLoading else { return false }
guard !isMainFrameProvisionalNavigationActive else { return false }
guard !hasCommittedDocument else { return false }
guard !isNavigationBlockedPendingConsent else { return false }
guard let intentURL else { return false }
return !isAboutBlankURL(intentURL)
}

nonisolated static func isRestoreStalled(
isRestoreNavigationPending: Bool,
isWebViewLoading: Bool,
isMainFrameProvisionalNavigationActive: Bool,
hasPendingRemoteNavigation: Bool,
hasCommittedDocument: Bool
) -> Bool {
guard isRestoreNavigationPending else { return false }
guard !isWebViewLoading else { return false }
guard !isMainFrameProvisionalNavigationActive else { return false }
guard !hasPendingRemoteNavigation else { return false }
return !hasCommittedDocument
}
}

extension BrowserPanel {
/// Whether browser native/SwiftUI fills should draw over the window root
/// backdrop. Mirrors terminal/markdown panel background decisions.
static func drawsConfiguredWebViewBackground(
isBlankPage: Bool,
usesTransparentBackground: Bool = false
) -> Bool {
drawsWebViewBackground(
isBlankPage: isBlankPage,
usesTransparentBackground: usesTransparentBackground,
opacity: GhosttyApp.shared.defaultBackgroundOpacity,
usesGhosttyGlassStyle: GhosttyApp.shared.defaultBackgroundBlur.isMacOSGlassStyle,
usesTransparentWindow: WindowBackgroundComposition.policy
.shouldUseTransparentBackgroundWindow(glassEffectAvailable: false)
)
}

nonisolated static func isBlankBrowserPageURL(_ url: URL?) -> Bool {
guard let url else { return true }
let value = url.absoluteString.trimmingCharacters(in: .whitespacesAndNewlines)
return value.caseInsensitiveCompare("about:blank") == .orderedSame
}

nonisolated static func isBlankBrowserPage(
liveURL: URL?,
currentURL: URL?,
pendingNavigationURL: URL?,
isMainFrameProvisionalNavigationActive: Bool
) -> Bool {
if isMainFrameProvisionalNavigationActive,
!isBlankBrowserPageURL(pendingNavigationURL) {
return false
}
if !isBlankBrowserPageURL(pendingNavigationURL),
isBlankBrowserPageURL(liveURL),
isBlankBrowserPageURL(currentURL) {
return false
}
return isBlankBrowserPageURL(liveURL) && isBlankBrowserPageURL(currentURL)
}

nonisolated static func drawsWebViewBackground(
isBlankPage: Bool,
usesTransparentBackground: Bool = false,
opacity: Double,
usesGhosttyGlassStyle: Bool,
usesTransparentWindow: Bool
) -> Bool {
if usesTransparentBackground {
return drawsWebViewBackground(
opacity: opacity,
usesGhosttyGlassStyle: usesGhosttyGlassStyle,
usesTransparentWindow: usesTransparentWindow
)
}
guard isBlankPage else { return true }
return drawsWebViewBackground(
opacity: opacity,
usesGhosttyGlassStyle: usesGhosttyGlassStyle,
usesTransparentWindow: usesTransparentWindow
)
}

nonisolated static func drawsWebViewBackground(
opacity: Double,
usesGhosttyGlassStyle: Bool,
usesTransparentWindow: Bool
) -> Bool {
!PanelAppearance.shouldUseClearContentBackground(
opacity: opacity,
usesGhosttyGlassStyle: usesGhosttyGlassStyle,
usesTransparentWindow: usesTransparentWindow
)
}
}
34 changes: 30 additions & 4 deletions Sources/Panels/BrowserHiddenWebViewDiscardManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ final class BrowserHiddenWebViewDiscardManager {
private(set) var lastDiscardReason: String?
private(set) var lastRestoreReason: String?
private(set) var restoredSessionShouldRenderWebView: Bool?
private(set) var isRestoreNavigationPending: Bool = false

var hasScheduledDiscard: Bool {
discardTimer != nil
Expand Down Expand Up @@ -239,6 +240,7 @@ final class BrowserHiddenWebViewDiscardManager {

func markDiscarded(reason: String, now: Date) {
isDiscardedForMemory = true
isRestoreNavigationPending = false
discardedAt = now
lastDiscardReason = reason
updateRestoredSessionRenderIntent(true)
Expand All @@ -248,20 +250,41 @@ final class BrowserHiddenWebViewDiscardManager {
func restoreIfNeeded(reason: String, performRestore: () -> Void) -> Bool {
guard isDiscardedForMemory else { return false }
cancel()
guard clearDiscardState(reason: reason) else { return false }
if isRestoreNavigationPending { return true }
lastRestoreReason = reason
updateRestoredSessionRenderIntent(nil)
performRestore()
return true
}

func noteRestoreNavigationStarted(reason: String) {
guard isDiscardedForMemory else { return }
isRestoreNavigationPending = true
#if DEBUG
cmuxDebugLog("browser.discard.restoreNavigation.start reason=\(reason)")
#endif
}

@discardableResult
func noteRestoreNavigationCommitted(reason: String) -> Bool {
isRestoreNavigationPending = false
return clearDiscardState(reason: reason)
}

func noteRestoreNavigationDidNotCommit(reason: String) {
guard isDiscardedForMemory else { return }
isRestoreNavigationPending = false
#if DEBUG
cmuxDebugLog("browser.discard.restoreNavigation.didNotCommit reason=\(reason)")
#endif
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved

@discardableResult
func reactivateWithoutNavigation(reason: String, performReactivate: () -> Void) -> Bool {
guard isDiscardedForMemory else { return false }
cancel()
guard clearDiscardState(reason: reason) else { return false }
updateRestoredSessionRenderIntent(nil)
performReactivate()
return true
return clearDiscardState(reason: reason)
}

func updateRestoredSessionRenderIntent(_ shouldRenderWebView: Bool?) {
Expand All @@ -272,14 +295,17 @@ final class BrowserHiddenWebViewDiscardManager {
func clearDiscardState(reason: String) -> Bool {
guard isDiscardedForMemory else { return false }
isDiscardedForMemory = false
isRestoreNavigationPending = false
discardedAt = nil
lastRestoreReason = reason
updateRestoredSessionRenderIntent(nil)
return true
}

func resetMetadata() {
cancel()
isDiscardedForMemory = false
isRestoreNavigationPending = false
discardedAt = nil
lastDiscardReason = nil
lastRestoreReason = nil
Expand Down
3 changes: 3 additions & 0 deletions Sources/Panels/BrowserNavigationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import WebKit
var didFinish: ((WKWebView) -> Void)?
var didFailNavigation: ((WKWebView, String) -> Void)?
var didCancelProvisionalNavigation: ((WKWebView) -> Void)?
var didBecomeDownload: ((WKWebView, Bool) -> Void)?
var didTerminateWebContentProcess: ((WKWebView) -> Void)?
var openInNewTab: ((URL) -> Void)?
var requestNavigation: ((URLRequest, BrowserInsecureHTTPNavigationIntent) -> Void)?
Expand Down Expand Up @@ -591,6 +592,7 @@ import WebKit
cmuxDebugLog("download.didBecome source=navigationAction")
#endif
NSLog("BrowserPanel download didBecome from navigationAction")
didBecomeDownload?(webView, navigationAction.targetFrame?.isMainFrame ?? true)
download.delegate = downloadDelegate
}

Expand All @@ -599,6 +601,7 @@ import WebKit
cmuxDebugLog("download.didBecome source=navigationResponse")
#endif
NSLog("BrowserPanel download didBecome from navigationResponse")
didBecomeDownload?(webView, navigationResponse.isForMainFrame)
download.delegate = downloadDelegate
}
}
Expand Down
Loading
Loading