-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(android): allow developers to provide logic for onRenderProcessGone in WebViewListener #6946
Conversation
…one in WebViewListener
The method should return true only if the app is "handling the situation", but there is no guarantee that the app is handling the situation just by having listeners as the listeners are an array of any WebView listeners, not just the onRenderProcessGone listeners, so it could have a listener for other events and not for onRenderProcessGone. What's the plan for handling the onRenderProcessGone on portals side? could we handle it in Capacitor so portals doesn't have to? There is an alternate plugin PR where the handling is forwarded to plugins and they can return true if they are handling onRenderProcessGone instead of using listeners. That's similar to how we handle shouldOverrideLoad capacitor/android/capacitor/src/main/java/com/getcapacitor/Bridge.java Lines 343 to 345 in 7e7c8b9
#6416 Also, as an alternative if this is going to be a portals only thing, portals could use their own WebViewClient that extends BridgeWebViewClient and implements onRenderProcessGone and that would require no changes in Capacitor. |
@jcesarmobile I like the solution in #6416 but it only provides access to that one specific WebViewClient method on the
onRenderProcessGone if it is added there. That WebViewListener can be used in plugins too.
Im tweaking the solution in this PR to give more control over the true/false return state |
@jcesarmobile also in regards to this
I was thinking about this. In Portals we need to give people full control since we don't know how the WebView is being used in an app, but in Capacitor right now I assume this is just an app crash. This is product decision but it might be nice if an error dialog displays and reloads the activity automatically or something. |
if (webViewListeners != null) { | ||
for (WebViewListener listener : bridge.getWebViewListeners()) { | ||
if (listener.onRenderProcessGone(view, detail)) { | ||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it should keep iterating to forward the event to all the listeners even if one of them returned true
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just noting this feedback hasn't been addressed here yet.
The logical combination will short-circuit, so once a true value is returned, I don't believe any other listener gets informed.
I'm just showing an alternative, which is similar to how the At the moment all the I have no preference on one over the other, probably makes sense to do all of them the same way. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The only thing is that this should go to main branch first and then cherry picked into 5.x once it's merged (or if it gets merged)
android/capacitor/src/main/java/com/getcapacitor/BridgeWebViewClient.java
Outdated
Show resolved
Hide resolved
…Client.java Co-authored-by: jcesarmobile <jcesarmobile@gmail.com>
…one in WebViewListener (#6946)
Portals developer app was crashing because they don't have a way to override this method in the WebViewClient in Capacitor. This adds the method to the interface so that it can be overridden via Portals. Not a breaking change.