react-native-webview: Invalid URI prop doesn't trigger onError or renderError callbacks
Bug description:
Providing an invalid source.uri
prop does not result in renderError
or onError
being executed. Instead the WebView remains in the loading state and a console.warn
for an unhandled promise rejection is displayed.
To Reproduce:
Use test
as your uri prop.
<WebView
source={{ uri: 'test' }}
onError={syntheticEvent => {
const { nativeEvent } = syntheticEvent;
console.warn('WebView error: ', nativeEvent);
}}
renderError={errorName => <Error name={errorName} />}
/>
Expected behavior:
Either onError
or renderError
should be executed.
Screenshots/Videos:
Environment:
- OS: macOS Mojave
- OS version: 10.14.4
- react-native version: 0.57.8
- react-native-webview version: 5.6.0
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 21 (1 by maintainers)
The
unable to open url
error message comes directly fromreact-native
linking, for iOS at least.As @mikehardy pointed out It looks like RN Webview tries to open urls that don’t match the originWhiteList in an external browser. Currently the
createOnShouldStartLoadWithRequest
function doesn’t have any error handler callback passed to it. Seems simple enough to add ahandleInvalidUrl
callback. May need to submit a PR to fix… unless someone beats me to it 😁UPDATE - looked into trying to patch this, but the
onError
callback prop expects a SyntheticEvent. Not sure how to pull that off without diving more into native code. Not worth the effort at this point as theconsole.warn
is already providing visibility to the error msg.As a workaround I just added a 10s timeout that will manually trigger the error screen. UX is okay but not optimal.
Any solution for this ?
This shouldn’t be closed, it’s still an issue. If you try to load some invalid URL there appears to be no way to avoid the promise rejection warning ?
My test case is to attempt to open a deep-link on a device that can’t handle it. Popular style to try, facebook: url could be ‘fb://page/225517294919485’ and if you don’t have facebook app installed you’ll get
Duplicate #1209 (also closed stale, no resolution though)
I ran into the same issue with WebView lately. Indeed,
onError
andrenderError
are not fired, butonHttpError
does fire, you can use it to display your error messages.i still have this error…error handlling in react native webview
+1