webview: isolate WKWebsiteDataStore and add async script message handler on macOS - #7
Closed
XinZhangBambu wants to merge 6 commits into
Closed
Conversation
On macOS, AddScriptMessageHandler() injected its window.<name> alias into the current document via synchronous RunScript() -> RunScriptSync(), which busy-waits with while(!done) wxYield() for evaluateJavaScript's completion handler. When the WKWebView is off-screen / in a background tab, macOS can throttle or suspend its WebContent process so the handler never fires, hanging the main thread. Add a two-argument overload AddScriptMessageHandler(name, runScriptSync). Only the macOS/WebKit backend overrides it; the base default ignores the flag and falls back to the existing single-argument API, so GTK and Edge need no changes. When runScriptSync is false on macOS the alias is injected asynchronously via evaluateJavaScript.
Map SetUserDataPathOption to a per-instance WKWebsiteDataStore so dual Studio processes do not share the default WebKit store. macOS 14+ uses dataStoreForIdentifier with a UUID persisted under the lock path; older OS keeps slot 0 on defaultDataStore and uses nonPersistent for others. Co-authored-by: Cursor <cursoragent@cursor.com>
Expose an explicit API to force WKWebsiteDataStore.nonPersistentDataStore before Create(). When enabled it takes precedence over SetUserDataPathOption path/slot selection. Co-authored-by: Cursor <cursoragent@cursor.com>
Collaborator
Author
|
Superseded by #8, which has the same diff but a clean commit history (rebased onto current master, only the three macOS WebView commits). |
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.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.nonPersistentDataStoreso cookies, local storage and caches are isolated per view and not written to disk. Must be called beforeCreate(). 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.Files
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.