WebView: recover when the content process dies (macOS) - #46
Open
jamierpond wants to merge 1 commit into
Open
Conversation
macOS jetsams WebContent processes routinely (memory pressure, sleep/wake). The delegate did not implement webViewWebContentProcessDidTerminate:, so WebKit told nobody and the view stayed an opaque dead rectangle until the app relaunched. Implement the selector: reload synchronously inside the callback (a reload issued from there survives WebKit's post-crash reset; a deferred load gets clobbered by it), and notify the owner via a new onContentProcessTerminated callback. HTML-string loads leave no back-forward item to reload — there the callback is the recovery path, and a loadHTML embedder re-issues its load from it. Tested by SIGKILLing the live WebContent process for real, both load shapes. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019fvd7ppoLmWHGmQrWUry9F
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
macOS kills WebContent processes routinely — memory pressure, sleep/wake cycles. When that happens, WebKit only tells the navigation delegate, via
webViewWebContentProcessDidTerminate:. The eacp delegate didn't implement that selector, so nobody heard about it and the WKWebView stayed a permanently dead (opaque black) view until the app relaunched. We hit this in production: an app opened in the morning after the machine slept overnight shows a black rectangle where the page should be, and only a force-quit fixes it.The fix implements the selector:
loadRequest:) gets clobbered by it and you end up on an emptyabout:blank.onContentProcessTerminatedcallback, deferred like the other owner callbacks.reloadcan't restore them (and a re-issuedloadHTMLStringagainst the replacement process dedupes to an empty document — WebKit quirk). There the owner callback is the recovery path: aloadHTMLembedder re-issues its load from it, which works.Tests kill the live WebContent process for real (SIGKILL via the test-only
_webProcessIdentifierSPI — the same death a jetsam delivers) and require the page to come back:delegateImplementsTheSelector— the respondsToSelector: contract with WebKitpageReloadsAfterContentProcessDies— custom-scheme URL load recovers on its ownhtmlStringEmbedderRecoversViaCallback— loadHTML embedder recovers via the callbackAll 65 WebView tests green, stable across repeated runs; full project builds clean.
The WebView2 backend has the analogous gap (
add_ProcessFailedisn't wired) — left for a follow-up since I can't test Windows from here.🤖 Generated with Claude Code
https://claude.ai/code/session_019fvd7ppoLmWHGmQrWUry9F