react-native-webview: Android: Vanilla android error page shown, despite setting renderError()
Bug description:
When using WebView with Android, there is a basic Android error page shown, alongside the content returned by renderError.
class WebView extends React.Component<WebViewProps> {
webViewRef = null;
reload = () => {
if (this.webViewRef) {
this.webViewRef.reload();
}
};
render() {
const { source } = this.props;
return (
<RNWebView
ref={webView => (this.webViewRef = webView)}
source={{ uri: 'blablabla_not_a_real_domain' }}
dataDetectorTypes="none"
useWebKit
renderLoading={() => (
<CenteredBlock>
<ActivityIndicator />
</CenteredBlock>
)}
renderError={(error, code, description) => {
let errorMessage;
if (Platform.OS === 'ios') {
errorMessage = description;
} else {
errorMessage = 'Something went wrong whilst loading this content.';
}
return (
<CenteredBlock>
<CenteredRow>
<WarningIcon width={32} height={32} />
</CenteredRow>
<Body centered>
{errorMessage}
</Body>
<CenteredRow>
<TextLink title="Retry" onPress={this.reload} />
</CenteredRow>
</CenteredBlock>
);
}}
startInLoadingState
/>
);
}
}
To Reproduce:
Expected behavior:
Render only the content returned by the renderError prop.
Screenshots/Videos:

Environment:
- OS: MacOS / Android
- OS version: Mojave / Nexus_5X_API_28_x86
- react-native version:
0.58.6 - react-native-webview version:
5.8.1
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19
@ec-harry you can custom your render message
renderError={() => { return ( <View style={{ width: '100%', height: '100%', backgroundColor: 'white', justifyContent: 'center', alignItems: 'center', }} > <Text style={{ color: 'black' }}>{'This is an error message'} </Text> </View> ); }}I don’t want this to be in the UI:
I would have expected that supplying a renderError prop would be a way to totally override any UI shown when there is an error.
To solve this issue make your
LoadingViewandErrorViewhaveStyleSheet.absoluteFillObjectcontainers.This is what the code looks like that renders the
WebViewon both iOS and Android:The reason they do this is because
webViewhandles the loading and error callbacks and then theotherViewis generated based on the results of those callbacks. In other words you can’t just render theotherViewbecause then thewebViewcould never stop loading via theonLoadingFinishcallback if you had anLoadingViewrendered.Another advantage of this approach is that it maintains your web navigation state between errors.
@arcesoj even if you add this, you still get a flash of what @cjpete is showing in their screenshot
… is this forgotten?
I managed to work around something. Basically I introduced a white View with delayed hide so I can bypass that ugly native screen showing between transitions.
Maybe someone can optimise this and translate it into a PR.
WebView.android.js