react-native-webview: Android - net::ERR_NAME_NOT_RESOLVED

Bug description:

When trying the example of usage Android returns an error Encountered an error loading page {"canGoBack": false, "canGoForward": false, "code": -2, "description": "net::ERR_NAME_NOT_RESOLVED", "loading": false, "target": 855, "title": "Webpage not available", "url": "https://reactnative.dev/"} Searching on Google i saw something about AppRegistry if this screen its going to be my root page, but is not my case, and trying on iOS everything is working just fine

To Reproduce:

Try the example of usage in a functional component

import React, {useRef, useState} from 'react';
import {SafeAreaView} from 'react-native';
// More imports

const HomeScreen = () => {
  // More stuff
  return (
    <SafeAreaView>
      <WebView source={{uri: 'https://reactnative.dev/'}} />
    </SafeAreaView>
  );
};

Expected behavior:

Screenshots/Videos:

iOS (working) Simulator Screen Shot - iPhone 11 - 2020-09-07 at 13 31 35

Android (not working) Screenshot_1599503315

Environment:

  • OS: macOS
  • OS version: 10.15.6
  • react-native version: 0.61.5
  • react-native-webview version: 10.8.3

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 42 (1 by maintainers)

Most upvoted comments

I’m experiencing this problem as well.

The emulator has no access to internet, so try it:

emulator -avd Nexus_5_API_28 -dns-server 8.8.8.8

related thread: https://stackoverflow.com/questions/42736038/android-emulator-not-able-to-access-the-internet

I had the same issue on my Mac, and it turned out that I did not have access to internet inside my Android simulator. I followed those instructions and now it works perfectly: https://stackoverflow.com/a/49332186.

I encountered this error sometimes when switching back and forth from Webview screen to different screens. In my testing, I was repeatedly clicking into Screen with WebView and going back to previous page.

Is this a problem when the Component unmounts?

In my case, it really was a DNS issue because the REST API did not provide IPv6 addresses. The Problem occurred in Android Firefox and Android Opera as well which was reason to look further.

It was solved by the API team when they enabled IPv6, so it seems react-native-webview does not re-try a lookup in IPv4 space after a IPv6 lookup has failed. This seems to be the same behaviour that Firefox Android & Opera Android exhibit so I would not see this as a bug, but a fault due to outdated development practises of our API team.

Thanky you for your patience and I hope this information helps someone.

You could use a UI logger for the website that way you can monitor what’s happening by inspecting the UI logger. You can checkout this library: https://www.npmjs.com/package/electrode-ui-logger

On Wed, Aug 2, 2023 at 2:57 PM ThaJay @.***> wrote:

In my case, the website loads just fine, the emulator has internet. This error comes up when the website inside webview tries to do a API request. How would I go about debugging this?

— Reply to this email directly, view it on GitHub https://github.com/react-native-webview/react-native-webview/issues/1619#issuecomment-1662262992, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3HCLG5DTE3LHFO3IVSH56LXTJMF7ANCNFSM4Q6X7UBA . You are receiving this because you commented.Message ID: @.*** com>

Any update or solution? It is happening to me on my physical device. Same implementation I use for android I am using it on my iOS device and it is working fine.

+1 happening on a Physical Android device. React-native version: 0.70.5 React Native webview: 11.13.0

For most case in android you have to check the internet connectivity from the simulator if the wifi is connected but there is no internet connectivity this error will persist.

Solution

  1. Try to close the simulator
  2. make sure you internet connection is active and is working
  3. re-open the simulator

This was how I got mine working

still searching for solutions…

this problem in my case is cause by the different file path on iOS and Android for example the iOS works fine but Android not well fix it by change the source

source={require('./tpl.html')}

to

source= {Platform.OS === 'ios' ? require('./tpl.html') : { uri: 'file:///android_asset/tpl.html' }}

Any update or solution? It is happening to me on my physical device. Same implementation I use for android I am using it on my iOS device and it is working fine.