Unable to load local file on Android
See original GitHub issueWhen trying to open a local webpage from tyhe local file system (using file://
) it works on iOS, but on Android we get an error:
Encountered an error loading page:
{
canGoBack: false,
canGoForward: false,
code: -1,
description: "net::ERR_ACCESS_DENIED",
loading: false,
target: 165,
title: "Webpagina niet beschikbaar",
url: "file:///data/user/0/com.twipepocv4/cache/data/36/Page-313.html",
}
This is my code:
<WebView
originWhitelist={['*']}
allowFileAccess={true}
source={{uri: "file:///data/user/0/<myapp>/cache/data/36/Page-319.html"}}
domStorageEnabled={true}
allowUniversalAccessFromFileURLs={true}
allowFileAccessFromFileURLs={true}
/>
I believe this has something to do with AllowFileAccessFromFileURLs but I can’t get it to work. Should any other permission be set?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:15
- Comments:28 (1 by maintainers)
Top Results From Across the Web
Unable to load local html file on API Level 30 - Stack Overflow
to show local html files in webView in api level 30, I used this code binding.webView.apply { visible() settings.apply { useWideViewPort ...
Read more >Can't open a Google file or folder - Android
On your Android device, open the app for Google Drive, Docs, Sheets, or Slides. At the top left, tap Menu Menu . Next...
Read more >Why can't Chrome read a local HTML file on Android? - Quora
You have to grant Chrome permission to access the Android File System. Then opening a html page including javascript, css and images should...
Read more >Android can't view local content after OS upgrade
If I run Files and view the Downloads folder, for example, it merely says "Can't load content at the moment". I've been using...
Read more >Loading in-app content - Android Developers
You can provide web-based content—such as HTML, JavaScript, ... Download the Android_symbol_green_RGB.png file to your local machine.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@tjensen is exactly right on the cause. Here’s a more detailed investigation and a workaround that we use. This only applies to Android 10.
Problem
react-native-webview
on Android handles theallowFileAccess
andallowUniversalAccessFromFileURLs
by callingview.getSetings().setAllowFileAccess()
in the Java code: https://github.com/react-native-community/react-native-webview/blob/47e9a0b/android/src/main/java/com/reactnativecommunity/webview/RNCWebViewManager.java#L484At the same time, setting
source
callsview.loadUrl()
. This results in a race where ifview.loadUrl()
executes before the security settings are updated, the page-load will fail.Workaround
We don’t load your local file until we’re sure the correct permissions have been set on the WebView.
On the component you have that renders
<WebView source={...}>
:componentDidMount
, set that variable to betrue
renderedOnce
is true:You guys are not doing properly, Proper ways is as follows: First install it using (If not installed), npm install --save react-native-webview // inside project root directory react-native link react-native-webview // it will link WebView with iOS and Android
I hope this will help you guys.