Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IndexedDB onversionchange event not fired in Chrome

I'm playing with the IndexedDB API from html5 spec in both Firefox and Chrome.

There something that's not working as expected I and want to share it here because I don't know if it's my fault or a browser bug.

According to the API, there's an event called onversionchange that's fired when you open a connection to a local database and the version number used is greater than the databases one. My problem is that this event is being fired in Firefox but not in Chrome.

Some sample code trying several modes:

var db;
var DB_VERSION = 5;
var openRequest = indexedDB.open("test_db", DB_VERSION);
openRequest.onsuccess = function(event) {
    db = openRequest.result;
};
openRequest.onversionchange = function(event) {
    console.log("This is the place where I can change db structure");
};
openRequest.onupgradeneeded = function(event) {
    console.log("This is the place where I can change db structure");
};

onversionchage event is not being fired even when I change the version number.

UPDATE As ebidel has answered, Chrome implementation does not follow the currently specification so, in order to have a cross browser client code, we need to handle two situations: onversionchange event and database.version manual comparison.

Here are a couple on links with code example: Chromium google group and HTML5 Rocks!

like image 641
PaquitoSoft Avatar asked Oct 30 '25 08:10

PaquitoSoft


1 Answers

Chrome's IndexedDB implementation is based off an older version of the spec which uses the older setVersion call rather than onversionchange/onupgradeneeded. Please star this issue: http://crbug.com/108223

like image 117
ebidel Avatar answered Oct 31 '25 22:10

ebidel