WebViewClient.onRenderProcessGone() called in random order when using multiple WebViews

1,373 views
Skip to first unread message

Simon Stahl

unread,
Apr 22, 2020, 2:37:36 PM4/22/20
to android-webview-dev
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:
  1. onRenderProcessGone() is not called first for the WebView that has actually crashed
  2. Inside onRenderProcessGone(), I cannot figure out if the passed WebView is the one that has crashed or not.

Torne (Richard Coles)

unread,
Apr 22, 2020, 2:42:36 PM4/22/20
to Simon Stahl, android-webview-dev
All of them have crashed. There is currently only one renderer process for any given app, so all WebViews are served by the same process, and so if that process crashes, *all* of the webviews are no longer usable and you need to handle them all appropriately: remove them from view hierarchies, destroy them, and start over.

If in future we start using more than one renderer process, onRenderProcessGone will be invoked only for the WebViews associated with the process which crashed, but that may still be more than one of them.
 

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/android-webview-dev/4de1fb94-5e5f-4776-91af-ffbe6b6b52a2%40chromium.org.
Message has been deleted

Simon Stahl

unread,
Apr 22, 2020, 2:48:49 PM4/22/20
to android-webview-dev, Simon Stahl
Thanks for the reply Richard. The reason why I want to know which WebView has caused the crash is that I would like to know what URL caused it. With the current implementation this seems impossible.

Torne (Richard Coles)

unread,
Apr 22, 2020, 2:52:20 PM4/22/20
to Simon Stahl, android-webview-dev

On Wed, 22 Apr 2020 at 14:48, Simon Stahl <java...@gmail.com> wrote:
Thanks for the reply Richard. The reason why I want to know which WebView has caused the crash is that I would like to know what URL caused it. With the current implementation this seems impossible.'

This is not possible to determine. The single renderer process  is handling all the web pages you have open and a crash could be caused by any of them (or by a bug in WebView itself), and there's no way for us to know either, which is why we can't give you that information - it doesn't exist, unfortunately.

--
You received this message because you are subscribed to the Google Groups "android-webview-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-webview...@chromium.org.
Reply all
Reply to author
Forward
0 new messages