jeremydurham/persist-js

#<HTMLObjectElement> has no method 'get'

thehydroimpulse opened this issue · 6 comments

var store = new Persist.Store('store', {
            swf_path: this.options.rootPath + 'assets/js/persist.swf'
        })
    store.save('h', 'heldadasdasdlo');
    console.log(store.get('h'));

Currently when I run the script I receive this error from the console.log output: (Chrome):
Uncaught TypeError: Object # has no method 'get'
(Firefox):
this.el.get is not a function
...key,val);return old_val;},remove:function(key){var val;key=esc(key);val=this.el....

Both are on line 138. I am using the latest version of persist and have tried everything on my end and still no go.

Thanks,
Daniel

Is this code that was previously working and has stopped working? Can you checkout a previous tag (such as 0.3.0) and verify that it works on that version?

It used to work about a few weeks ago, then I downloaded a new copy of it and now it stopped working. I tested it on version 0.3.0 and that error seems to have disappeared, but now I get
Uncaught Error: QUOTA_EXCEEDED_ERR: DOM Exception 22 (Chrome) and nothing on firefox.

I also noticed it doesn't load the swf file anymore after trying 0.3.0, the path is correct.

Let me know if you need any other info.

Thanks,
Daniel

I guess before it used flash automatically for some reason, now it uses localstorage. I'll keep trying to debug on my side.

I pushed an update to the flash backend that may help resolve this issue. Please give me your feedback on whether it helps at all. There is a known issue where using the flash backend and then immediately calling save/set/get/etc will throw the error you have specified, but the update should allow the flash backend to be used as soon as it is loaded, instead of causing this.el to be undefined.

localstorage can be very finicky with Chrome and Firefox, especially with the file protocol (in Firefox) or with cookies disabled (in Chrome). Version 0.3.0 did not handle these issues well, but HEAD does, so if you are running via file:// or without cookies, HEAD will probably choose flash, whereas 0.3.0 would have picked localstorage.

mmmmm.... Well I built a new version of the updated file and no go. The this.el issue is fixed though, but now it's the Uncaught Error: QUOTA_EXCEEDED_ERR: DOM Exception 22 for chrome and it works on firefox though.

I did some research on that error and have found things related to chrome's limit to localstorage. Also a stack overflow post had this to say: http://stackoverflow.com/questions/2603682/is-anyone-else-receiving-a-quota-exceeded-err-on-their-ipad-when-accessing-local

I opened up the un-minified version and on line 706 (where the error is), I commented it and the error went away and started to work except, well the key was obviously null then.

Thanks,
Daniel

Ok well I guess I fixed the issue... It seems chrome is the only browser that cannot handle overload of data, other browsers have their own way of dealing with this issue that's why it worked in firefox.

Quick fix: (This is the whole set method, line 701)

 set: function(key, val ) {
          // expand key
          key = this.key(key);

          //Fix for chrome "Uncaught Error: QUOTA_EXCEEDED_ERR: DOM Exception 22".
          try{
            // set value
            this.store.setItem(key, val);
          } catch(e){
            if(e.code == 22){
              this.store.clear();
            }
          }
          //End of fix;

          return val;
        }

Thanks,
Daniel