theredled
theredled

Reputation: 1040

IndexedDB put/add failing silently in Chrome (for all websites)

After some successful development using IndexedDB on Chrome, all write operations just stopped working without giving any error. Everything is fine with Safari.

Here is a straightforward sample not working:

var db = null;
var req = indexedDB.open("TestDb", 1);

req.onsuccess = function(event) {
    db = event.target.result;
    db.onerror = function(event) {
      error('Error: ', event.target.errorCode);
    };

    var os = db.transaction(['users'], "readwrite").objectStore('users');
    req = os.put({id: 2, name: 'Benoît'});

    req.onsuccess = function (event) {
        console.log('Put success', event.target.result);

        var os = db.transaction(['users'], "readwrite").objectStore('users');
        var req = os.get(2);
        req.onsuccess = function(event) {
            console.log('Get success', event.target.result);
        }

    };
    req.onerror = function (event) {
        console.log('error', event);
    };
};

req.onupgradeneeded = function(ev) {
    console.log('db upgradeneeded', ev);
    var db = ev.target.result, objectStore;

    if (ev.oldVersion < 1) {
        objectStore = db.createObjectStore('users', {keyPath: "id"});
        objectStore.createIndex("name", "name", {unique: false});
    }
};

Resulting in console log:

Put success 2

Get success undefined

Upvotes: 2

Views: 1722

Answers (1)

theredled
theredled

Reputation: 1040

Actually there was not enough space on disk.

As said by @Joshua Bell, the query successes but the transaction aborts, so you need to watch transaction.onabort to raise an error message.

Upvotes: 4

Related Questions