Closed guykileveryone closed 8 years ago
I got exactly the same issue with the plugin and demo on Android.
The download of the app update data itself works as files are downloaded to 'app' directory, but on reload files are not found with cdvfile protocol in URL and 404ing. Using an URL like "file:///storage/emulated/0/app/app.js", they are accessible.
I'm using Cordova 5 with Android Platform Support 4.0.0.
Full list of plugins is:
cordova-plugin-whitelist 1.0.0 "Whitelist" org.apache.cordova.file 1.3.3 "File" org.apache.cordova.file-transfer 0.5.0 "File Transfer"
I seem to be having the same problem. using cordova 5 with android platform support 4.0.0
installed plugins cordova-plugin-file 2.0.0 "File" cordova-plugin-file-transfer 1.1.0 "File Transfer" cordova-plugin-whitelist 1.0.0 "Whitelist"
Is anyone has solution? I've got the same problem too.
This is because the whitelist plugin rejects cdvfile://: https://github.com/apache/cordova-plugin-whitelist/pull/6... see my fork here: https://github.com/agamemnus/cordova-plugin-whitelist.
Thanks @agamemnus! I've realized it already. I had problems of implementing Cordova-app-loader. Finally I've got it all working using the proper CSP:
<meta http-equiv="Content-Security-Policy" content="default-src * 'self' cdvfile://*; style-src 'unsafe-inline' 'self' cdvfile://*; script-src 'self' 'unsafe-eval' cdvfile://*">
See my implementation here for example: https://github.com/murlex/UpdatableApp
I tried your header, and that does not require a whitelist plugin change, so well done there! However, it doesn't take into account content://
, code inline in html files, or JS code referenced from outside. You also don't need to repeat things after the default-src.
I am currently using this:
<meta http-equiv="Content-Security-Policy" content="* * 'self' default-src 'unsafe-inline' 'unsafe-eval' http://* https://* data: cdvfile://* content://*;">
(Note that the permissions reset for scripts and styles you add script-src or style-src -- they aren't additive, and hence why I lump it all in default-src. If you want to separate it out, that will make the header much longer, and watch out for missing things)
Thank you! I'll take these corrections. I just a new in Cordova development so still possibly makes the new guy mistakes :)
What I did on my side is to put <access origin="cdvfile://*" />
in my config.xml
the same problem happens to me on all my image resources. I am not using the whitelist plugin. any idea?
In Cordova 5, you have to or you get errors. Check your console in chrome. Not sure if this is intended.
+1 No choice from Cordova Android 4.x. The whitelist plugin is mandatory to make it work.
I don't really understand why that was done... and then without any serious testing to compound the issue. :/
This is Cordova. Not the plugin.
Yes, I should have been clearer.
Thank you murlex, I have follow your implementation and It's great. I did a simple implementation just for understanding my issue on Android. Now I believe I'm ready to implement my Single Page App based on Android there.
Thank YOU!!!
I can not solve this for love nor money. I have tried everything, but still when the app seems to download the new files and reboot to load them using the cdvfile:// protocol I just get a red failed line in the Chrome console (running from the app on the device) for every failed resource (such as app.js) and it fails. It then reboots back to shipped files. It does not work.
@ashleycoker, this is exactly what I'm finding. Been working on this for a day so far.
I can get the local files to load fine and execute, but when it downloads from my file server, it seems to download successfully and append to the DOM but it never runs. I don't get the permission error anymore after using @agamemnus's recommendation, so I don't think its that.
However, when it defaults back to the factory default, it seems to work fine. I'm thinking there's a silent CDV permission issue I'm encountering
I'm using cordova 5 with android platform support 4.0.0
installed plugins cordova-plugin-file 2.0.0 "File" cordova-plugin-file-transfer 1.1.0 "File Transfer" cordova-plugin-whitelist 1.0.0 "Whitelist"
I wonder how this plugin works. I have a mechanism that uses a server's last-updated date for my own update system. I don't think it is broken in 5 but not sure.
Tried running on Desktop chrome and apart from not finding cordova.js
and having to add CORS on my file server, it seems to be working perfectly but still not joy on android thogh :sob:
Not sure if this will help some unfortunately soul out there in my shoes but check out @murlex's excellent tutorial repo: https://github.com/murlex/UpdatableApp for guidance
What made it all work for me was adding the following to config.xml
<allow-navigation href="*://*/*"/>
@ashleycoker, I'm not super familiar with phonegap but it should be the same as long as you're building it locally using something like the command line. No idea how it works if you do a remote build through Adobe
Hi,
i thought i'd share my experiences on this since it was driving me crazy. What made it work for me was adding <access origin="cdvfile://*"/>
to the config.xml file - even though it already had a <access origin="*"/>
entry.
Additionally - since my app is built in AngularJS - i had to modify the imgSrcSanitizationWhitelist
property of the $compileProvider to contain cdvfile://
:
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|file|blob|cdvfile|content):|data:image\//);
Maybe this is helpful for someone.
@darinda Dude you're a lifesaver thank you for that. I couldn't get any of my files to reference the downloaded content properly.
I'm using Ionic and I didn't need to add the extra <access origin="cdvfile://*"/>
to config.xml, just the stuff for $compileProvider
@darinda worked for me too. Thanks!
Closing the issue since it appears to have been resolved, if it is still an issue please reopen.
As an aside this information should be added to the README.md
You guys rock! This took me forever to find
The approach <access origin="cdvfile://*" />
mentioned in the post of @ObjectiveTruth at Sep 6 works fine in android 6.0.1 Nexus 5X. Thank you!
I cant get this to work on IOS. I have used the meta tag
$compileProvider.imgSrcSanitizationWhitelist(/^\s*(https?|file|blob|cdvfile|content):|data:image\//);
and that compiler code but I still get told its unsupported.
@Ross-Rawlins are you using some WKWebview or UIWebview? It seems WKWebview doesn't support custom URL schemes at all ..
@nicowenterodt So if I use ionic plugin add https://github.com/driftyco/cordova-plugin-wkwebview-engine.git for iOs and it will break the cdvfile path?! I am having this issue and can not get it to work in iOs no matter what I add!!
I have cordova-app-loader working perfectly in browser and ios, but android devices (including the simulator) cannot seem to load the files. This results in BOOTSTRAP_OK not being set and it loading all the original app files again.
Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/CordovaPromiseFS.is?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/cordova—app—loader—complete.is?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/autoupdate.is?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/app.is?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/style.css?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/countries.js?1430969702286 Failed to load resource: the server responded with a status of 404 (Not Found) cdvfile://localhost/persistent/app/style.css?1430969702286
EDIT: I just checked on a fresh install of the demo Cordova App Loader and got the same result. It fails at the 'update' stage.