-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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: add plugin hooks for WebViewClient.onRenderProcessGone #1574
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1574 +/- ##
==========================================
+ Coverage 71.82% 72.61% +0.78%
==========================================
Files 23 23
Lines 1796 1800 +4
==========================================
+ Hits 1290 1307 +17
+ Misses 506 493 -13 see 2 files with indirect coverage changes 📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more |
Nice work. I face webview hang , found no solution. I will try your cordova-android and write a plugin |
Given that the Android Docs states
I think it's unsafe to attempt to "prevent" a crash or continue using the webview. I think at minimum the webview needs to be recreated. I do agree that it is definitely useful for debugging or crashlytics however. The |
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.
Tested both on API 24 and API 33 emulators, both of which I believe works as expected.
On API 24, the hook is simply not invoked and the process will simply crash.
On API 33, the hook is invoked before the crash, allowing the system to gracefully handle the crash and to potential recover from it.
930b777
to
4c9bb96
Compare
Yep! Agree that more work would be needed if some kind of crash recovery was needed... returning I've tweaked this a bit, so should be good for another review when you have time @breautek |
4c9bb96
to
dc7bc1e
Compare
dc7bc1e
to
fb6b87f
Compare
Alright, had to do some tweaks in cordova-android to test it, but at the core I think this is good. I implemented the on hook in @Override
public boolean onRenderProcessGone(final WebView view, RenderProcessGoneDetail detail) {
if (webView.getEngine().getView() == view) {
// Is the crash view the cordova webview?
LOG.e(TAG, "CORDOVA WEBVIEW CRASHED!");
return true;
}
return false;
} Naturally returning true prevents the app from crashing and actually yields the webview still visible, but in an unsafe manner. Returning false will crash the application, assuming nothing else actually handles the webview. To be clear, I'm not suggesting to implement something like this into this PR, I'm just using the PR to demonstrate what is possible.
I do agree with this sentiment. I see that PluginManager will still call through all plugins hooks even if a plugin has already return true, so I think that covers that. |
Co-authored-by: Norman Breau <[email protected]>
Thanks for the review and merge @breautek 🍻 Agree with the wording change there. We definitely want plugins to leave the return value alone unless they really know what they're doing! |
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
Awesome work, thanks @peitschie This feature will be available in the upcoming cordova-android@12 release. |
…1574) * feat: add plugin hooks for WebViewClient.onRenderProcessGone * Update framework/src/org/apache/cordova/CordovaPlugin.java Co-authored-by: Norman Breau <[email protected]> --------- Co-authored-by: Norman Breau <[email protected]>
Platforms affected
Android
Motivation and Context
This change allows more advanced handling of the webview render process termination. This can be useful for capturing additional information, or even conceivably allow the crash to be prevented should a plugin choose to.
Description
Expose the WebViewClient.onRenderProcessGone method down to plugins, and allow a plugin to interrupt the crash should it choose so.
Testing
I created the hello world cordova application and added a javascript call to load
chrome://crash
(recommended by Android docs as the best way to trigger a renderer crash).Checklist
(platform)
if this change only applies to one platform (e.g.(android)
)