Julien Fouilhé February 2016

IndexedDB.open callbacks not called on Chrome

I am trying to use IndexedDB, and everything was working well, up until a few hours ago when my .open() callbacks stopped being called on Chrome (tested on Safari and it worked fine).

RT.prototype.setupIndexedDB = function (callback) {
  var dbName = "test";
  var dbVersion = 1;
  var indexedDB = window.indexedDB ||
                  window.webkitIndexedDB ||
                  window.mozIndexedDB;

  console.log("setup indexed db");
  var request = indexedDB.open(dbName, dbVersion);
  request.onsuccess = function(e) {
    console.log("db request success");
  };

  request.onblocked = function(e) {
    console.log("DB open blocked", e);
  };

  request.onerror = function(err) {
    console.log("error", err);
  };

  request.onversionchange = function(err) {
    console.log("onversionchange", err);
  };

  request.onupgradeneeded = function(e) {
    console.log("upgrade needed");
  };
};

I looked into the Chrome developer tools IndexedDB and nothing is there...

Anyone has an idea on what's happening?

Thank you

EDIT: Completely restarting the browser did the trick, but I'm still very interested in knowing what happened.

Answers


dgrogan February 2016

Were you experimenting with deleting the database around the same time? IndexedDB can get into a weird (though correct, according to the spec) state if there's a blocked pending deleteDatabase operation. E.g. the code below. If all else fails you can check chrome://indexeddb-internals, which will tell you if there are any pending open or delete operations that are mucking things up.

var request = indexedDB.open("test", 1);
request.onblocked = function(e) {
  console.log("DB open blocked", e);
};

request.onerror = function(err) {
  console.log("DB open error", err);
};

request.onupgradeneeded = function(e) {
  console.log("DB open upgrade needed");
};

request.onsuccess = function(e) {
  db = request.result;
  console.log("DB open success");
  db.onversionchange = function(e) {
    console.log("DB got a versionchange event")
  }
  request = indexedDB.deleteDatabase("test");
  request.onsuccess = function(e) {
    console.log("delete success will not be called")
  }
  request.onblocked = function(e) {
    console.log("delete was blocked");
    request = indexedDB.open("test", 1);
    request.onsuccess = function(e) {
      console.log("success won't be called");
    };
    request.onblocked = function(e) {
      console.log("blocked won't be called", e);
    };
    request.onerror = function(err) {
      console.log("error won't be called", err);
    };
    request.onupgradeneeded = function(e) {
      console.log("upgradeneeded won't be called");
    };
  };
};

Post Status

Asked in February 2016
Viewed 1,766 times
Voted 7
Answered 1 times

Search




Leave an answer