axemclion / jquery-indexeddb

An IndexedDB Plugin for Jquery.
Other
195 stars 71 forks source link

InvalidStateError when accessing idbRequest.result in onblocked event #12

Closed timukasr closed 11 years ago

timukasr commented 11 years ago

Simple way to reproduce in Chrome:

$.indexedDB('testDB', {
    version: 1,
    upgrade: function(trans) {
          trans.createObjectStore('store', {keyPath: 'key'});
    }
}).objectStore('store').put({key: 1}).done(function() {
    $.indexedDB('testDB').deleteDatabase()
        .progress(function() {
            console.log('Never called due to error');
        }).done(function(db, event) {
            console.log(event.type); // success
        });
});

Raising the onblocked event in this context seems to be Chrome's bug, but it's easy way to reproduce the bug of jquery-indexeddb, which happens when accessing result property of idbRequest in the onblocked event. Simple fix would be to just remove .result from idbRequest variable on line 46. After that, no errors are thrown and progress function is called.

axemclion commented 11 years ago

Happens only in older versions of Chrome, looks like this is fixed in the later Chrome versions. So, added a try catch to prevent this error.

SHA: 4780bfadcbcaeb38dae446ee4043616db6adfd73