question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invalid URI prop doesn't trigger onError or renderError callbacks

See original GitHub issue

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: Screen Shot 2019-04-26 at 11 43 56 AM

Screen Shot 2019-04-25 at 11 43 56 AM

Environment:

  • OS: macOS Mojave
  • OS version: 10.14.4
  • react-native version: 0.57.8
  • react-native-webview version: 5.6.0

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:8
  • Comments:20

github_iconTop GitHub Comments

3reactions
townofdoncommented, Oct 25, 2021

The unable to open url error message comes directly from react-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 a handleInvalidUrl 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 the console.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.

3reactions
mikehardycommented, May 26, 2020

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

Error: Could not open URL 'fb://page/225517294919485': No Activity found to handle Intent { act=android.intent.action.VIEW dat=fb://page/225517294919485 flg=0x10000000 }
promiseMethodWrapper@http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:3126:45
http://10.0.2.2:8081/index.bundle?platform=android&dev=true&minify=false:203466:37

etc etc

Duplicate #1209 (also closed stale, no resolution though)

Read more comments on GitHub >

github_iconTop Results From Across the Web

react.js Replace img src onerror
I am trying to replace the image with a default image if the image does not exist and there is a 404 error....
Read more >
React Error Handling And Reporting With Error Boundary ...
In this article, we'll explore the concept of error boundaries in a React application. We'll work through an example app to see how...
Read more >
Error Handling in React 16 – React Blog
Introducing Error Boundaries​​ To solve this problem for React users, React 16 introduces a new concept of an “error boundary”. Error boundaries ...
Read more >
How to Handle Errors in React
Let's look at the various ways you can handle React errors.
Read more >
DataSearch - Reactive Manual
Props · componentId String unique identifier of the component, can be referenced in other components' react prop. · dataField String or Array database...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found