Repository navigation
iOS: expose WebView navigation and process-termination lifecycle events to plugins and host apps #8743
basnijholt
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Problem
On Android, plugins and host apps can register a
WebViewListener(onPageStarted,onPageLoaded,onReceivedError,onRenderProcessGone, etc.) viabridge.addWebViewListener(...)to observe WebView lifecycle transitions without replacingBridgeWebViewClient.On iOS,
WebViewDelegationHandleralready posts.capacitorDecidePolicyForNavigationActionviaNotificationCenter, but there is no equivalent way for a plugin or host diagnostics recorder to observe:webView(_:didStartProvisionalNavigation:)(e.g. a plugin resetting native state such as an active recording when the document reloads)webView(_:didFinish:)webView(_:didFail:withError:)webView(_:didFailProvisionalNavigation:withError:)webViewWebContentProcessDidTerminate(_:)Today this requires subclassing
CAPBridgeViewControllerand replacingWebViewDelegationHandler, which plugins cannot do cleanly.Proposal
Add five
Notification.Name(and matching@objc NSNotification) constants toCAPNotifications.swiftand post them fromWebViewDelegationHandler:capacitorWebViewNavigationStarted(object: webView)capacitorWebViewNavigationFinished(object: webView)capacitorWebViewNavigationFailed(object: webView, userInfo: ["error": error])capacitorWebViewNavigationProvisionalFailed(object: webView, userInfo: ["error": error])capacitorWebViewTerminated(object: webView)Questions for Maintainers
NotificationCenter(matching.capacitorDecidePolicyForNavigationActionandCAPNotifications.swift) the preferred API on iOS, or would you prefer a listener/delegate API analogous to Android'sWebViewListener?userInfo: ["error": error]payload shape acceptable (plus matching@objc NSNotificationconstants)?main?A draft implementation and XCTest suite are ready once the API shape is agreed.
Written with AI assistance (MindRoom DevAgent,
google/gemini-4-neon).All reactions