webview: isolate WKWebsiteDataStore and add async script message handler on macOS - #8
Merged
lanewei120 merged 1 commit intoSep 11, 2026
Conversation
Add two opt-in, macOS/WebKit-only capabilities to wxWebView. SetNonPersistentWebsiteDataStore() makes the WKWebView use WKWebsiteDataStore.nonPersistentDataStore, so that cookies, local storage and caches are isolated per view and never written to disk. It must be called before Create(). The macOS backend also honours SetUserDataPathOption() to isolate the on-disk store when a persistent one is used. The new AddScriptMessageHandler(name, runScriptSync) overload allows injecting the handler bootstrap script asynchronously. The synchronous injection spins wxYield() waiting for evaluateJavaScript, which never completes when the WKWebView is off-screen and its WebContent process is throttled, hanging the main thread. The default implementations of all new virtuals are no-ops or forward to the existing single-argument overload, so wxGTK and wxMSW are unchanged.
XinZhangBambu
force-pushed
the
fix/webview-webkit-data-store-isolation-clean
branch
from
September 10, 2026 10:03
b1b125b to
5d3a57b
Compare
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.
Adds two macOS/WebKit-only capabilities to
wxWebView, both opt-in and no-ops on other backends. Rebased onto currentmaster, so this branch contains only the three commits below and touches only the macOS WebView files.1. Non-persistent website data store (macOS)
New virtuals on
wxWebView:SetNonPersistentWebsiteDataStore(bool enable = true)IsNonPersistentWebsiteDataStore() constOn the macOS/WebKit backend this makes the
WKWebViewuseWKWebsiteDataStore.nonPersistentDataStore, so cookies, local storage and caches are isolated per view and never written to disk. Must be called beforeCreate(). The default implementations are no-ops, so GTK and Edge are unaffected.The macOS backend also honours
SetUserDataPathOption()to isolate the on-disk data store when a persistent store is used.2. Async
AddScriptMessageHandleroverloadNew virtual overload:
AddScriptMessageHandler(const wxString& name, bool runScriptSync)The default implementation ignores the flag and forwards to the existing single-argument overload, so GTK and Edge behave exactly as before. Only the macOS/WebKit backend honours
runScriptSync == false.Motivation: on macOS the handler bootstrap script is injected with a synchronous
RunScriptSync()that spinswxYield()waiting forevaluateJavaScript. If theWKWebViewis off-screen its WebContent process gets throttled, the callback never fires, and the main thread hangs. Passingfalseinjects the alias asynchronously instead.Commits
webview: add runScriptSync overload for macOS AddScriptMessageHandlerwebview: isolate WKWebsiteDataStore via SetUserDataPathOption on macOSwebview: add SetNonPersistentWebsiteDataStore for macOS WKWebViewFiles
include/wx/webview.h,interface/wx/webview.h— new virtuals + docsinclude/wx/osx/webview_webkit.h,src/osx/webview_webkit.mm— macOS implementationNote on overlap with #4
#4 solves the same
AddScriptMessageHandlerhang by changing the signature toAddScriptMessageHandler(const wxString& name, bool runScriptSync = true)across all backends. This branch instead adds a separate virtual overload so existing backend signatures stay untouched. The two approaches conflict — only one should be merged.Supersedes #7 (same diff, but that branch carried three already-merged commits from my fork's
masterin its commit list).