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" />


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)
I solved it by adding
proyect/android/src/AndroidManifest.xmlandroid:usesCleartextTraffic="true"If it doesn’t work by adding
android:usesCleartextTraffic="true".You can also add
android:networkSecurityConfig="@xml/network_security_config"in yourandroid/app/src/main/AndroidManifest.xmlfile.Creating
network_security_config.xmlfile inandroid/app/src/main/res/xmlIt may ignore some cert error.
Tested in
And I am still looking for a way to ignore all certificate error. Especially self-signed certificate.
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.
onReceivedErroris always called for the download URL, including other lifecycle methods likeonPageStartedandonPageFinished.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(); } } /><manifest ... > <uses-permission android:name="android.permission.INTERNET" /> ... </manifest>android:usesCleartextTraffic=“true” still not work.
Same issue. show on phone, simulator work fine.