When using multiple WebViews at the same time in an app and one of them crashes the renderer, it is not possible to figure out which one the crash caused.
If I do something like this:
public class MyWebViewClient extends WebViewClient {
private static AtomicBoolean crash = new AtomicBoolean(true);
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
// Crash the first WebView that finishes the page loading
if (crash.compareAndSet(true, false)) {
crashPage(view);
}
}
protected void crashPage(WebView view) {
Logger.e("MyWebViewClient", "crashPage() ... crashing WebView: " +view.hashCode());
// Do something bad that will crash the renderer process
view.evaluateJavascript("javascript:(function() { txt = \"a\"; while(1){ txt += \"a\"; } })();", null);
}
@Override
public boolean onRenderProcessGone(WebView view, RenderProcessGoneDetail detail) {
Logger.e("MyWebViewClient", "onRenderProcessGone() ... WebView: " +view.hashCode());
return true; // Return true so the other callbacks are called too
}
...
}
When I run this in an app that uses four WebViews, I get a log output like this:
MyWebViewClient: crashPage() ... crashing WebView: 214164866
MyWebViewClient: onRenderProcessGone() ... WebView: 250503274
MyWebViewClient: onRenderProcessGone() ... WebView: 76159286
MyWebViewClient: onRenderProcessGone() ... WebView: 64416164
MyWebViewClient: onRenderProcessGone() ... WebView: 214164866
The two issues I have are:
- onRenderProcessGone() is not called first for the WebView that has actually crashed
- Inside onRenderProcessGone(), I cannot figure out if the passed WebView is the one that has crashed or not.