react-native-webview / react-native-webview

React Native Cross-Platform WebView
https://github.com/react-native-community/discussions-and-proposals/pull/3
MIT License
6.31k stars 2.96k forks source link

invalid url causing crash in ios #3384

Closed akshgods closed 2 days ago

akshgods commented 2 months ago

Bug description:

If we pass invalid url we are getting crash

actual url: https://www.hindustantimes.com/ht-img/img/2024/03/27/550x309/Akshay_Kumar_1711524357605_1711524357751.jpg

invalid url which causing crash: '%3Ca%20_blank%20href=https://www.hindustantimes.com/ht-img/img/2024/03/27/550x309/Akshay_Kumar_1711524357605_1711524357751.jpg'

Error handling functions not returning anything.

 onError={(e) => {
            console.log('onError:: ', e);

          }}
          onHttpError={(e) => {
            console.log('onHttpError:: ', e);

          }}
          renderError={(e) => {
            console.log('renderError:: ', e);
          }}

To Reproduce:

Reproduce is simple, just use this url in your webview url:

url={'%3Ca%20_blank%20href=https://www.hindustantimes.com/ht-img/img/2024/03/27/550x309/Akshay_Kumar_1711524357605_1711524357751.jpg'}

now open webview you will get application getting crash.

Expected behavior:

it should not get crashed , it will throw error in one of error handling function.

 onError={(e) => {
            console.log('onError:: ', e);

          }}
          onHttpError={(e) => {
            console.log('onHttpError:: ', e);

          }}

let me know what changes required or what we can do it to solved this?

Environment:

netmaxt3r commented 2 months ago

@akshgods can you check issue is reproducible on latest version?

akshgods commented 2 months ago

@netmaxt3r yes confirmed with latest available version. Simulator Screen Shot - iPhone 14 - 2024-04-15 at 13 51 03

Screenshot 2024-04-15 at 1 52 53 PM

code to test:

<WebView source={{ uri: '3Ca%20_blank%20href=https://reactnative.dev/' }} 
       style={{ flex: 1 }}
       onError={(e) => {
        console.log('onError:: ', e);
      }}
      onHttpError={(e) => {
        console.log('onHttpError:: ', e);
      }}
      renderError={(e) => {
        console.log('renderError:: ', e);
      }}
       />

Environment:

OS: Mac OS version: 13.2.1 (22D68) "react-native": "0.73.6", "react-native-webview": "^13.8.5"

netmaxt3r commented 2 months ago

I am getting different results.

on iOS its just console.warn with Error opening URL: [Error: Unable to open URL: .... image Simulator Screenshot - iPhone 15 Pro - 2024-04-15 at 20 57 40

on Android it does call onError with nativeEvent {"canGoBack": false, "canGoForward": false, "code": -2, "description": "net::ERR_NAME_NOT_RESOLVED", "loading": false, "target": 3, "title": "", "url": "http://3ca%20_blank%20href%3Dhttps//reactnative.dev/"} followed by two calls to renderError with null error image

In either case app does not crash

akshgods commented 2 months ago

@netmaxt3r but im getting same error as i sent before.

Simulator Screen Shot - iPhone 14 - 2024-04-16 at 13 40 08

but im not getting warning , can you share your code and url used?

also send react native version and plugin version used

akshgods commented 2 months ago

@netmaxt3r i understand you code diffrence

you used http:// in starting of url

just use this without http:

source={{ uri: '3Ca%20_blank%20href=https://reactnative.dev/' }}

netmaxt3r commented 2 months ago

@akshgods i havent added http protocol, it is added by android as the url is malformed it cannot detect the protocol, where as in ios it defaults to file protocol to relative path as seen in the warning

    return (
      <WebView source={{ uri: '3Ca%20_blank%20href=https://reactnative.dev/' }}
               style={{ flex: 1 }}
               onError={(e) => {
                 console.log('onError:: ', e.nativeEvent);
               }}
               onHttpError={(e) => {
                 console.log('onHttpError:: ', e);
               }}
               renderError={(e) => {
                 console.log('renderError:: ', e);
               }}
      />
    );
  "dependencies": {
    "react": "18.2.0",
    "react-native": "0.73.6",
    "react-native-webview": "^13.8.5"
  }
github-actions[bot] commented 1 week ago

Hello 👋, this issue has been opened for more than 2 months with no activity on it. If the issue is still here, please keep in mind that we need community support and help to fix it! Just comment something like still searching for solutions and if you found one, please open a pull request! You have 7 days until this gets closed automatically