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

Uncaught TypeError: savedFS is not a function #205

Open Defcon0 opened 7 years ago

Defcon0 commented 7 years ago

When running imgcache I get:

Uncaught TypeError: savedFS is not a function at imgcache.js:633

Am I doing something wrong or is it a bug?

chrisben commented 7 years ago

Could you please explain how you're running imgcache? This part of code should be triggered when running with Chrome.

If you run the following in your browser console, what response do you get ? window.requestFileSystem || window.webkitRequestFileSystem

Defcon0 commented 7 years ago

I use the angular wrapper (angular-imgcache.js#^1.1.0) and get the error when using the Chrome developer tools after running my ionic app on an Android device. If you need further detail, don't hesitate to contact me again :-)

Initially I get:

INFO: ImgCache initialising imgcache.js:49 INFO: LocalFileSystem opened imgcache.js:49 INFO: Local cache folder opened: cdvfile://localhost/persistent/imgcache/ imgcache.js:49 INFO: .nomedia file created.

After running window.requestFileSystem || window.webkitRequestFileSystem

I get:

function (type, size, successCallback, errorCallback) { argscheck.checkArgs('nnFF', 'requestFileSystem', arguments); var fail = function(code) { if (errorCallback) { …

Strange thing is that it doesn't happen everytime. Just now and then. But when the error message pops up I mentioned in my first post, window.requestFileSystem || window.webkitRequestFileSystem returns undefined.

chrisben commented 7 years ago

I've just merged a PR that fixes browser detection for ionic into master, could you please check with that version?

adascal commented 7 years ago

@chrisben Problem seems to be not fixed. Still can see it on Android devices

ghost commented 7 years ago

I'm also seeing this happen, even with the latest version of ionic-img-cache installed.

jyve commented 7 years ago

Same issue here, with version 1.2.0

csicky commented 6 years ago

Hi, I had the same issue. window.requestFileSystem was undefined and because of this it entered the wrong path, in Chrome instead of Cordova and savedFS also was undefined.

The solution for me was to properly wait for deviceready event and only then to init ImageCache and start using it. I hope it helps others with same problem.

Very helpful library, thx for making it!

chrisben commented 6 years ago

Thanks @csicky for pointing this out. It's actually part of the documentation:

If you're using imgcache.js with PhoneGap/Cordova, ImgCache.init() must be called after the onDeviceReady event has been triggered, not before!

Defcon0 commented 6 years ago

Maybe this should be put somewhere more prominent :-)

chrisben commented 6 years ago

I also accept pull requests for the README :) @Defcon0 : did that fix your problem ? Let me know so that we can close this issue.

Defcon0 commented 6 years ago

@chrisben Ah, ok, I'll check later on today (or on weekend) and reply afterwards.

chrisben commented 6 years ago

README paragraph now bold. There's also a bold statement in the CORDOVA.md document.

By the way I also merged my long standing 2.x branch, 2.0.0 is out now!

Defcon0 commented 6 years ago

@chrisben Still no luck :-( The problem occurs with this code:

document.addEventListener('deviceready', function() {
    ImgCache.$init();
});

called in app.module.js.

I have imgcache.js 1.1.0 and angular-imgcache 1.2.0.

renanmoraes commented 6 years ago

for me it also does not work at all on android.

yurii-zadryhun commented 6 years ago

I'm also seeing this problem on android (cordova). I call init function when deviceready has been triggered. image

chrisben commented 6 years ago

Could someone please test the following and check what the console logs display:

document.addEventListener('deviceready', function() {
    // init
   ImgCache.init();
   console.log('isCordova?', ImgCache.helpers.isCordova());
   console.log('requestFileSystem', window.requestFileSystem);
   console.log('cordova', typeof cordova);
   console.log('phonegap', typeof phonegap);
   console.log('platformId', (cordova||phonegap).platformId);
});
ragunathans commented 6 years ago

You need to install following plugins to fix the savedFS is not a function issue.

ionic cordova plugin add cordova-plugin-file --save
ionic cordova plugin add cordova-plugin-device --save
ionic cordova plugin add cordova-plugin-file-transfer --save
vdias38 commented 4 years ago

I've faced this issue, but found that cordova.js was missing on my app