How to access webview errors on native android?

Hello Guys,

I am trying to capture the error that occurred on Webview cycle on native Android. I checked the capacitor provide addWebViewListener that provides useful information related to Webview but it doesn’t return error information in public void onReceivedError(WebView webView). So my main question is how I can access that information on native Android? Should I create another WebViewClient that is inherited from BridgeWebViewClient or there is the proper way to access webview errors?

Hello, @pratik0softgames

To capture error information in the WebView cycle on native Android, you can override the onReceivedError method in your WebViewClient. This method is called when an error occurs during the loading of a resource. Here’s how you can do it:

webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
// Handle the error here
}

@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    super.onReceivedError(view, request, error

To capture error information in the WebView cycle on native Android, you can override the onReceivedError method in your WebViewClient. Here’s a basic example of how you can do this:

webView.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
super.onReceivedError(view, errorCode, description, failingUrl);
// Handle the error here
Log.e(“WebViewError”, errorCode + “:” + description);
}

// For API 23 and above
@Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
    super.onReceivedError(view, request, error);
    // Handle the error here
    Log.e("WebViewError", error.getErrorCode() + ":" + error.getDescription());
}

});

In this code:

The first onReceivedError method is for handling errors in API levels below 23.
The second onReceivedError method is for API level 23 and above, which provides more detailed information about the error.
Make sure to log the error or handle it as needed in your application. If you’re using a custom WebViewClient that extends BridgeWebViewClient, you can still override these methods in your subclass to capture the error information.

Remember to check the Android documentation for the latest best practices on managing WebView objects and handling errors. If you need further assistance, feel free to ask!

Best Regard,
Ryan1969