react-native-webview: Error on opening download file link on android "Domain: undefined Error code -1"

  • Site was opened
  • Trying to open file download link
  • File downloaded successfully
  • Webview crashed with the next error message “Error loading page. Domain: undefined. Error Code: -1. Description: net::ERR_FAILED” I tried it for 2 different app builds and for different download file links.

One of the tested urls http://sources.codenet.ru/file/609/example.rar

<WebView source={{ uri: 'http://sources.codenet.ru/file/609/example.rar' }} />

To AndroidManifest added <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Screenshot_2019-11-29-20-04-38

Screenshot_2019-11-29-20-28-22~3

Environment:

  • OS: Android

  • OS version: 7

  • react-native version: 0.61.3

  • react-native-webview version: 7.4.3

  • Working fine for Android 10 emulator

  • Working fine for Android 7 emulator

  • Crashing for Android 7 device

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 15
  • Comments: 36 (3 by maintainers)

Most upvoted comments

I solved it by adding proyect/android/src/AndroidManifest.xml

android:usesCleartextTraffic="true"

Captura de Pantalla 2020-05-03 a la(s) 12 18 41 p  m Captura de Pantalla 2020-05-03 a la(s) 12 20 40 p  m

If it doesn’t work by adding android:usesCleartextTraffic="true".

  1. You can also add android:networkSecurityConfig="@xml/network_security_config" in your android/app/src/main/AndroidManifest.xml file. img

  2. Creating network_security_config.xml file in android/app/src/main/res/xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">add your domain like www.google.com</domain>
        <domain includeSubdomains="true">or local ip address 192.168.1.101</domain>

        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </domain-config>

    <base-config cleartextTrafficPermitted="false" />
</network-security-config>

It may ignore some cert error.

Tested in

  • “react-native”: “0.63.4”
  • “react-native-webview”: “^11.2.0”

And I am still looking for a way to ignore all certificate error. Especially self-signed certificate.

If anyone has a workaround solution, please share here.

PR #1221 works around this bug but I haven’t been able to get it code reviewed by maintainers…

After more investigation with @trcoffman we’ve determined this to be an underlying WebView bug. We made a very stripped down pure Android WebView app. onReceivedError is always called for the download URL, including other lifecycle methods like onPageStarted and onPageFinished.

I found a filed Chrome bug and followed up there with more details for their team.

There is potential workarounds that could be done to ignore the lifecycle methods when a download just happened, but that solution isn’t the most appealing.

same issue here… work on ios , work on simulator or expo release, not in prod…

@vpankov have you got any solutions? I am also facing the same issue.

We are experiencing the same bug as well on android.

Hi @AmitPandya007
No, I didn’t. I just added onError handler, that reload webview. So user still see error message for about 2 seconds, but file is successful downloaded and user can use app after page reloaded. So it’s not a solution of the bug, but user experience process was saved and user doesn’t need to reload the app. <WebView source={{ uri: 'http://example.page' }} ref={ref => { this.webView = ref; }} onError={ ()=>{ this.webView.reload(); } } />

Screenshot (108) same issue, i might thinking about , enable that option somewhere, its was in android stupid known as <manifest ... > <uses-permission android:name="android.permission.INTERNET" /> ... </manifest>

android:usesCleartextTraffic=“true” still not work. bug

Same issue. show on phone, simulator work fine.