From 6cc4694e1ea0b6767ece0f6c59e1bc396bdca91e Mon Sep 17 00:00:00 2001 From: James Magahern Date: Sat, 6 Sep 2025 22:56:51 -0700 Subject: [PATCH] attempt to fix stale tabs --- App/Browser View/BrowserViewController.swift | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/App/Browser View/BrowserViewController.swift b/App/Browser View/BrowserViewController.swift index f2cc585..c5cef7a 100644 --- a/App/Browser View/BrowserViewController.swift +++ b/App/Browser View/BrowserViewController.swift @@ -594,6 +594,19 @@ class BrowserViewController: UIViewController // Blur url bar, if applicable toolbarController.urlBar.textField.resignFirstResponder() + + // If this tab's web content process was jettisoned while in background, + // its current page may appear blank and url be nil. Proactively reload + // when the tab becomes active again to restore state. + if tab.contentProcessTerminated { + if webView.url != nil || tab.url != nil { + webView.reload() + } else if let home = tab.homeURL { + tab.beginLoadingURL(home) + } else { + webView.reload() + } + } } override func target(forAction action: Selector, withSender sender: Any?) -> Any? { @@ -618,6 +631,18 @@ class BrowserViewController: UIViewController override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(animated) becomeFirstResponder() + + // If the app resumed and the current tab's web content process was + // terminated while in background, ensure we restore it now. + if currentTab.contentProcessTerminated { + if webView.url != nil || currentTab.url != nil { + webView.reload() + } else if let home = currentTab.homeURL { + currentTab.beginLoadingURL(home) + } else { + webView.reload() + } + } } internal func updateScriptBlockerButton() {