From e99f23d07e4b1ac3d83933be2641b66dc6139e4e Mon Sep 17 00:00:00 2001 From: Brent Simmons Date: Sun, 26 Jul 2026 11:29:04 -0700 Subject: [PATCH] =?UTF-8?q?Recover=20from=20WebKit=20content-process=20ter?= =?UTF-8?q?mination=20=E2=80=94=20refresh=20the=20preloaded=20web=20view?= =?UTF-8?q?=20pool=20on=20foreground,=20and=20never=20render=20into=20a=20?= =?UTF-8?q?web=20view=20whose=20process=20died.=20Fixes=20#5310.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iOS/Article/WebViewController.swift | 9 ++++++++- iOS/Article/WebViewProvider.swift | 10 ++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/iOS/Article/WebViewController.swift b/iOS/Article/WebViewController.swift index 1cd63b890..09624067c 100644 --- a/iOS/Article/WebViewController.swift +++ b/iOS/Article/WebViewController.swift @@ -37,6 +37,8 @@ final class WebViewController: UIViewController { return view.subviews[0] as? PreloadedWebView } + private var webViewProcessDidTerminate = false + private lazy var contextMenuInteraction = UIContextMenuInteraction(delegate: self) private var isFullScreenAvailable: Bool { return AppDefaults.shared.articleFullscreenAvailable && traitCollection.userInterfaceIdiom == .phone @@ -454,6 +456,7 @@ extension WebViewController: WKNavigationDelegate { } func webViewWebContentProcessDidTerminate(_ webView: WKWebView) { + webViewProcessDidTerminate = true fullReload() } @@ -554,11 +557,15 @@ private extension WebViewController { func loadWebView(replaceExistingWebView: Bool = false) { guard isViewLoaded else { return } - if !replaceExistingWebView, let webView = webView { + // Never render into a web view whose content process died — the load + // can fail silently, leaving the article view blank. + if !replaceExistingWebView, !webViewProcessDidTerminate, let webView = webView { self.renderPage(webView) return } + webViewProcessDidTerminate = false + coordinator.webViewProvider.dequeueWebView { webView in webView.ready { diff --git a/iOS/Article/WebViewProvider.swift b/iOS/Article/WebViewProvider.swift index 25b5eab92..3f739fb1a 100644 --- a/iOS/Article/WebViewProvider.swift +++ b/iOS/Article/WebViewProvider.swift @@ -7,6 +7,7 @@ // import Foundation +import UIKit import RSCore import WebKit @@ -21,12 +22,21 @@ import WebKit articleIconSchemeHandler = ArticleIconSchemeHandler(coordinator: coordinator) super.init() replenishQueueIfNeeded() + NotificationCenter.default.addObserver(self, selector: #selector(handleWillEnterForeground(_:)), name: UIApplication.willEnterForegroundNotification, object: nil) } func replenishQueueIfNeeded() { operationQueue.add(WebViewProviderReplenishQueueOperation(queue: queue, articleIconSchemeHandler: articleIconSchemeHandler)) } + // Pooled web views can lose their content process while the app is in the + // background. A load into a dead web view can fail silently, showing blank — + // so start over with fresh web views. + @objc func handleWillEnterForeground(_ note: Notification) { + queue.removeAllObjects() + replenishQueueIfNeeded() + } + func dequeueWebView(completion: @escaping (PreloadedWebView) -> Void) { operationQueue.add(WebViewProviderDequeueOperation(queue: queue, articleIconSchemeHandler: articleIconSchemeHandler, completion: completion)) operationQueue.add(WebViewProviderReplenishQueueOperation(queue: queue, articleIconSchemeHandler: articleIconSchemeHandler))