Android Webview : Not allowed to load resource error library project - android

My Application has custom webviews loading html (react based webpack build) from local assets folder. When I tried to load the webview , I see the error
"Not allowed to load local resource : file:///android_asset/index.html/#/initialize?..."
Please note : the route ("index.html/#/..") added along with the html. If I load the html only, it works fine.
My application has permission to read and write from storage.
I cannot use loadDataWithBaseURL because the 2nd parameter expects a html data.

Sorry - it was a simple issue.
When using react route - the URL should be :
file:///android_asset/index.html#/initialize?...
and not file:///android_asset/index.html/#/initialize?...
Notice the extra '/' after the .html

Related

local HTML file not loaded in Chrome for Android

Trying to load a local HTML file (SPA including assets, js, css) on Chrome on Android. File is loaded, html seems to be parsed but shows nothing.
When debugging this remotely (USB/adb) I got this error in the console:
Not allowed to load local resource: content://com.huawei.filemanager.share.fileprovider/root/storage/emulated/0/Download/test1/index.html
Basically it seems the file is not loaded at all.
What can be done ? Help, Tx.

load local file in webview ios using http protocol. (Create Webview server in android and iOS)

Is there any way to create the server in android and iOS to run a web-view? I want to run a local HTML file in a web-view with a local-host URL.
I have already searched for this on the following links but could not find any solution.
GCDWebServer
local-http-server-for-ios
Supercharging the Android WebView
Hereby i am sharing the actual scenario :
1) Download ".zip" file from server and save it on application library directory for offline use.
2) ".zip" file contents html and javascript files. It works when the HTML page is simple. But if the HTML references something else, i.e. a JavaScript file also in the library directory (with an absolute path like ), it will fail to load.
3) I need to setup local server in my device, On application launch local server starts and upload the application library directory on local server and then load the content using local host. See below example
Using Library directory path
file:////Users/prince/Library/Developer/CoreSimulator/Devices/75EF3DD7-DFD1-4EDB-9A6B-9FBA60F4D98C/data/Containers/Data/Application/32F774B2-E811-4281-A37A-DC8A5183B7C8/Library/Application%20Support/adededfe6c1c7bd8b5d5adb19861b9e0/Responses/36b8f6a8d6f58d58f117856dc80b0d37/abc.html
Using localhost path
http://localhost:8080/Application%20Support/adededfe6c1c7bd8b5d5adb19861b9e0/Responses/36b8f6a8d6f58d58f117856dc80b0d37/abc.html
Does anyone know why this happens, and how to resolve the issue?

Xamarin Android Webview: Not allowed to load local resource "file:///android_asset/*.css" source: (1)?

I have a small CSS file I use with JavaScript to override the CSS on a website loaded in a WebView. I would like to load it locally instead of need to access it online. I have gotten the JavaScript to work perfectly when the file is uploaded to a temporary filehost, so it works fine, but something regarding permissions won't let me use it as an asset.
I've tried setting permissions, changing the WebView's settings to allow MixedContentMode always, tried using LoadData, etc, but it always throws the "Not allowed" issue. The asset has the AndroidAsset build action.
string jsToInject = "javascript: var link=document.createElement('link');link.href='file:///android_asset/newsOverride.css';link.type ='text/css'; link.rel ='stylesheet';document.getElementsByTagName('head')[0].appendChild(link);";
view.LoadUrl(jsToInject);
When the link.href field is set to the file hosted on the web somewhere, it loads the CSS as expected. But when it's selected as an asset it simply throws
I/chromium(11626): [INFO:CONSOLE(1)] "Not allowed to load local resource: file:///android_asset/newsOverride.css", source: (1)
All I've been able to find on the error is with Xamarin Forms, not Xamarin Android, any help is appreciated.
This issue should implementing the WebViewClient with a shouldInterceptRequest override like this thread.
Kitkat kills: Not allowed to load local resource: file:///android_asset/webkit/android-weberror.png

Using Pdf.js in Android hybrid app to load local files

I am developing an app for android using Sencha touch and Cordova which needs to load PDF files.I found the Child browser support on PDF is not there for Android.So I decided to use PDF.js.I am using the following line of code to open the PDF file :
window.open(\''+ ROOT_FOLDER+'/app/util/PDFJS/web/viewer.html?file='+ROOT_FOLDER + '<Path to PDF file>\'
ROOT_FOLDER is the local file path URL like file://app/utils.."
But the pdf is not loading in this case and it is throwing an exception like
XMLHttpRequest cannot load file:///android_asset/www/<path to PDF file>. Cross origin requests are only supported for HTTP.
Please let me know how to fix this issue, or how to load PDF files from local location using PDF.js
If you want to load the files from local location, then it should be present in the same folder with viewer.html. In short the PDF should not be outside the main folder where all these html and js files are present.

Unknown Chromium Error -6 when loading local images in Android Webview

I'm working on a Worklight project that downloads a zip file, unpacks it, and stores the files in the specific documents directory of the platform (in iOS that's NSDocumentDirectory, on Android I'm using getFilesDir()). The file consists of one HTML file and several images, located in a sub directory (media). Downloading and unzipping works fine on both platforms. After the unzip process I'm loading the contents of the HTML file into an existing div (since this is a Worklight app, everything is in one HTML file).
Here things become complicated:
The image tag sources in the HTML file that I've downloaded are relative to the HTML file (e.g. 'media/myimage.jpg'). When I inject the HTML file into the Worklight HTML file (which is located in the App bundle/package), the base URL changes and the images can't be found anywhere. I fixed this by writing native functions that rewrite all the image tags in the downloaded HTML file to point to an absolute URL (iOS: /var/mobile/Applications/<identifier>/Documents/, Android: /data/data/<id>/files/). This works fine on iOS, but on Android it causes the HTML to only load partially. LogCat then shows:
Unknown chromium error: -6
If I keep the files as they are, the HTML loads correctly, but obviously with broken images. I've also tried to change the URLs to file:///data/data/<id>/files/ [...], which also causes the HTML to not load completely. I have really no idea what is causing this problem. The app already has the WRITE_EXTERNAL_STORAGE permission.
Does anyone have an idea how to fix this? Thank you!
Turns out this error was caused by having images that are larger than 1500px in width. After scaling them down, the error disappears. Must be a problem with the Android webview, I guess.

Categories

Resources