chrisben / imgcache.js

JS library based on the File API to cache images for offline recovery (target: cordova/phonegap & chrome)
Other
826 stars 216 forks source link

Fixes cordova detection in cordova browser platform #199

Closed Maistho closed 7 years ago

Maistho commented 7 years ago

fixes #159 fixes #160

also affects #164 ?

This sets the browser platform in cordova to be just a regular browser platform.

FromBucketsToRainBarrels commented 7 years ago

do i still need to follow these steps ?

https://github.com/chrisben/imgcache.js/issues/159

Maistho commented 7 years ago

@FromBucketsToRainBarrels what steps?

Basically either:

  1. Don't put cordova.js in when running on a browser or
  2. Until this gets merged, make the appropriate edits (the same as this PR) in imgcache.js after installing.
FromBucketsToRainBarrels commented 7 years ago

I'm sorry, I should be more specific.

should I add <meta http-equiv="Content-Security-Policy" content="default-src * 'unsafe-inline' 'unsafe-eval'; media-src *"> to my index.html ?

Maistho commented 7 years ago

You'll always need to set an appropriate CSP. I would not set one that permissive.

Have a read and decide what would be a good fit for you:

FromBucketsToRainBarrels commented 7 years ago

I tested my appwith ionic serve

image

I am able to access the cached file at filesystem::http:// ..... as you can see in the screen shot above

I tested my appwith ionic browser serve --livereload

image

I get the file without any issue from the same location

then I upload my browser project onto my remote server and try to access it from there and I can not get my files, if you look at this screenshot below I checked if the imgchache.js has the return (typeof cordova !== 'undefined' || typeof phonegap !== 'undefined') && window.parent._cordovaNative; changes that you made. and they are also there.

image

if you want to check the live example of my app running with the latest changes

http://fbtrb.tanzeelrana.me/

I even tried to hack my way to get the cached file by changing the path "cdvfile://localhost/temporary/imgcache/65e41411723b32de1e9d6e79863fbd909a3034de.png"

to

"filesystem:http://localhost/temporary/imgcache/65e41411723b32de1e9d6e79863fbd909a3034de.png"

but still I get the same error

image

project repo url : https://github.com/FromBucketsToRainBarrels/weather_social_app travis-ci : https://travis-ci.org/FromBucketsToRainBarrels/weather_social_app

Maistho commented 7 years ago

Well, ionic serve does not create window.cordova.

I looked at your live site, and it seems to work for me as long as I accept the request to store files. That being said, you should use a fallback if a user blocks the filesystem api, or is on a non-chrome browser.

Also, you don't seem to have the changes live on your site.

Regardless, your issues don't seem related.

FromBucketsToRainBarrels commented 7 years ago

yes, as you suggested, I removed the cordova.js file from my browser project for now. I spent too much time trying to get this to work last night. I re built the project and reverted those changes. I guess I'll add cordova.js file back to my browser project once your request is merged to the master. Thanks for helping on it. glad you replied, I would have had been stuck on it otherwise

chrisben commented 7 years ago

Thanks a lot @Maistho , I don't follow the ionic platform at all, glad it solves something there.

krzkz94 commented 7 years ago

This still does not fix the problem for me, in electron.

Here is the original

Helpers.EntryToURL = function (entry) { if (Helpers.isCordovaAndroidOlderThan4() && typeof entry.toNativeURL === 'function') { return entry.toNativeURL(); } else if (typeof entry.toInternalURL === 'function') { // Fix for #97 return entry.toInternalURL(); } else { return entry.toURL(); } };

It keeps returning entry.toInternalURL(); while what you need if you have loaded cordova.js (for the yummy plugins of course) is entry.toURL();

A simple junk fix that i have added is to check on the second conditional if it is actually cordova.

Helpers.EntryToURL = function (entry) { if (Helpers.isCordovaAndroidOlderThan4() && typeof entry.toNativeURL === 'function') { return entry.toNativeURL(); } else if (Helpers.isCordova() && typeof entry.toInternalURL === 'function') { // Fix for #97 return entry.toInternalURL(); } else { return entry.toURL(); } };

This works perfectly fine in electron.