IndexedDB exception in Chrome 21 beta

2,199 views
Skip to first unread message

Abhinav Asthana

unread,
Jul 12, 2012, 4:50:17 AM7/12/12
to chromiu...@chromium.org
I have been using IndexedDB for my extension called Postman in the Chrome Web Store. Just yesterday I started receiving some bug reports like these: 

Numeric transaction modes are deprecated in IDBDatabase.transaction. Use "readonly" or "readwrite".
Uncaught Error: NotFoundError: DOM IDBDatabase Exception 8 requester.js:2768
postman.indexedDB.addCollection requester.js:2768
postman.collections.addRequestToCollection requester.js:2230
(anonymous function) requester.js:2443
f.event.dispatch jquery.min.js:3
f.event.add.h.handle.i jquery.min.js:3

Would be great if anyone can shed some light on this. Is this an upcoming change in Chrome or something has changed in the IndexedDB spec itself? Is there something I might be doing wrong? Some sample code:

var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;

var trans = db.transaction(["requests"], IDBTransaction.READ_WRITE);

This seems to be working fine till now and has been mentioned in almost all resources I looked up. 


PhistucK

unread,
Jul 12, 2012, 6:18:51 AM7/12/12
to Abhinav Asthana, chromiu...@chromium.org

--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msg/chromium-html5/-/wzqt2GobuVEJ.
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-html5/?hl=en.

Joshua Bell

unread,
Jul 12, 2012, 12:16:40 PM7/12/12
to Abhinav Asthana, chromiu...@chromium.org
Yes, we recently updated Chrome's IndexedDB implementation here to match the spec. The numeric constants were removed, you need to pass in strings. So that we didn't break deployed code the methods currently accept both numbers and strings during a transition period, but we plan to drop number support eventually. This is tracked in https://bugs.webkit.org/show_bug.cgi?id=85315 - in the mean time we issue console warnings so that app developers have some motivation to update before the legacy support is dropped.

The above just explains the console warning. The exception is unrelated. Per the spec (and implementation) NotFoundError is thrown by IDBDatabase.transaction() when the specified object store is not found in the database, so it looks like that could be an error in your web app's logic?

Abhinav Asthana

unread,
Jul 12, 2012, 2:25:41 PM7/12/12
to chromiu...@chromium.org, Abhinav Asthana
Thanks Joshua! That clears up my doubts about the exception error.

As you said the database call seems to be failing because there are no object stores and that indeed is the case. Here is the code that I am using to initialize IndexedDB: 

var request = indexedDB.open("postman", "Postman request history");
request.onsuccess = function (e) {
  var v = "2";
  postman.indexedDB.db = e.target.result;
  var db = postman.indexedDB.db;
  if (v !== db.version) {
    var setVrequest = db.setVersion(v);
    setVrequest.onfailure = function (e) {
    };
    setVrequest.onsuccess = function (e) {
      //Only create if does not already exist
      if (!db.objectStoreNames.contains("requests")) {
        var requestStore = db.createObjectStore("requests", {keyPath:"id"});
        requestStore.createIndex("timestamp", "timestamp", { unique:false});
      }}

    //Has a call to IDBDatabase.transaction()
    getAllRequests();
  };

  setVrequest.onupgradeneeded = function (evt) {
  };
}
else {
  //Do something here
}
request.onfailure = postman.indexedDB.onerror;

I just came across this thread which says a call to db.transaction should not be present in a setVersion call. This does show up as an error at the db.transaction call inside getAllRequests() in my code:

Uncaught Error: InvalidStateError: DOM IDBDatabase Exception 11 requester.js:2988

Is this error the cause for the object stores not getting created? I am wondering if there is anything else which might be wrong with the initialization code. I'll move the db.transaction call into an oncomplete event and see if this fixes the issue.

On Thursday, July 12, 2012 9:46:40 PM UTC+5:30, Joshua Bell wrote:
Yes, we recently updated Chrome's IndexedDB implementation here to match the spec. The numeric constants were removed, you need to pass in strings. So that we didn't break deployed code the methods currently accept both numbers and strings during a transition period, but we plan to drop number support eventually. This is tracked in https://bugs.webkit.org/show_bug.cgi?id=85315 - in the mean time we issue console warnings so that app developers have some motivation to update before the legacy support is dropped.

The above just explains the console warning. The exception is unrelated. Per the spec (and implementation) NotFoundError is thrown by IDBDatabase.transaction() when the specified object store is not found in the database, so it looks like that could be an error in your web app's logic?

On Thu, Jul 12, 2012 at 3:18 AM, PhistucK wrote:
Well, that is what the specifications document says -
On Thu, Jul 12, 2012 at 11:50 AM, Abhinav Asthana wrote:
I have been using IndexedDB for my extension called Postman in the Chrome Web Store. Just yesterday I started receiving some bug reports like these: 

Numeric transaction modes are deprecated in IDBDatabase.transaction. Use "readonly" or "readwrite".
Uncaught Error: NotFoundError: DOM IDBDatabase Exception 8 requester.js:2768
postman.indexedDB.addCollection requester.js:2768
postman.collections.addRequestToCollection requester.js:2230
(anonymous function) requester.js:2443
f.event.dispatch jquery.min.js:3
f.event.add.h.handle.i jquery.min.js:3

Would be great if anyone can shed some light on this. Is this an upcoming change in Chrome or something has changed in the IndexedDB spec itself? Is there something I might be doing wrong? Some sample code:

var IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;

var trans = db.transaction(["requests"], IDBTransaction.READ_WRITE);

This seems to be working fine till now and has been mentioned in almost all resources I looked up. 


--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msg/chromium-html5/-/wzqt2GobuVEJ.
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html5+unsubscribe@chromium.org.

--
You received this message because you are subscribed to the Google Groups "Chromium HTML5" group.
To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html5+unsubscribe@chromium.org.

Alec Flett

unread,
Jul 12, 2012, 3:11:51 PM7/12/12
to Abhinav Asthana, chromiu...@chromium.org
Yep, you got that exactly right. Here's the announcement:

Also, here's the announcement about the strings vs integers:


To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.

Abhinav Asthana

unread,
Jul 13, 2012, 3:04:14 AM7/13/12
to chromiu...@chromium.org, Abhinav Asthana
Thanks for the links Alec. The bug seems to have been fixed. Is there some sort of an official doc for the IndexedDB implementation for Chrome? I was thinking of writing a tutorial/how-to for newcomers and a reference of some sort would be great.


On Friday, July 13, 2012 12:41:51 AM UTC+5:30, Alec Flett wrote:

Parashuram Narasimhan

unread,
Jul 13, 2012, 11:03:38 AM7/13/12
to chromiu...@chromium.org, Abhinav Asthana
I started writing some tutorials for IndexedDB at http://axemclion.github.com/IndexedDB. This may be helpful. If you want to add something to the tutorials, you can send in a pull request to https://github.com/axemclion/IndexedDB

Joshua Bell

unread,
Jul 13, 2012, 11:51:39 AM7/13/12
to chromiu...@chromium.org, Abhinav Asthana, Parashuram Narasimhan
On Fri, Jul 13, 2012 at 8:03 AM, Parashuram Narasimhan <n.para...@gmail.com> wrote:
I started writing some tutorials for IndexedDB at http://axemclion.github.com/IndexedDB. This may be helpful. If you want to add something to the tutorials, you can send in a pull request to https://github.com/axemclion/IndexedDB

This is awesome! As you test out the various browsers, have you noticed any implementation differences, other than those I list below?
 
On Friday, July 13, 2012 12:04:14 AM UTC-7, Abhinav Asthana wrote:
Thanks for the links Alec. The bug seems to have been fixed. Is there some sort of an official doc for the IndexedDB implementation for Chrome? I was thinking of writing a tutorial/how-to for newcomers and a reference of some sort would be great.

We're working hard to ensure that the Chrome IndexedDB implementation matches the spec and is compatible with all of the other browser implementations. Chrome specific documentation should not be necessary. In fact, we've been contributing to the docs on MDN:


While we have a handful of known bugs around edge cases in the spec that apps are unlikely to hit, and presumably some bugs we're not aware of yet, there are only two deviations from the spec that you need to be aware of:
  • Versioning - Chrome still uses the older db.setVersion() API for versioning, rather than open(name, version) / onupgradeneeded callback now defined in the spec. We're actively working to switch over to the mechanism in the spec, and hope to land that for M22. (Our plan is to maintain the old API as well during a transition period, with console warnings.)
  • Blobs - Chrome does not support storing Blob/File/FileList objects in IDB stores (this support is not mentioned directly in the IDB spec, but rather indirectly by reference to the HTML "structured clone algorithm" which enumerates these types). With Chrome's multiprocess architecture this turns out to be nontrivial to do in an efficient way; we have designs in progress, but no ETA on support. 
We're landing patches like crazy to match the spec, so the closer to Canary you're running the more spec-compliant the implementation should be. We'll continue to send announcement mail here for any breaking changes apps are likely to hit.
 

To post to this group, send email to chromiu...@chromium.org.
To unsubscribe from this group, send email to chromium-html...@chromium.org.

Abhinav Asthana

unread,
Jul 14, 2012, 8:44:07 AM7/14/12
to chromiu...@chromium.org, Abhinav Asthana, Parashuram Narasimhan
@Parashuram
Great stuff! Very helpful.

On Friday, July 13, 2012 9:21:39 PM UTC+5:30, Joshua Bell wrote:
On Fri, Jul 13, 2012 at 8:03 AM, Parashuram Narasimhan wrote:
I started writing some tutorials for IndexedDB at http://axemclion.github.com/IndexedDB. This may be helpful. If you want to add something to the tutorials, you can send in a pull request to https://github.com/axemclion/IndexedDB

This is awesome! As you test out the various browsers, have you noticed any implementation differences, other than those I list below?
 
On Friday, July 13, 2012 12:04:14 AM UTC-7, Abhinav Asthana wrote:
Thanks for the links Alec. The bug seems to have been fixed. Is there some sort of an official doc for the IndexedDB implementation for Chrome? I was thinking of writing a tutorial/how-to for newcomers and a reference of some sort would be great.

We're working hard to ensure that the Chrome IndexedDB implementation matches the spec and is compatible with all of the other browser implementations. Chrome specific documentation should not be necessary. In fact, we've been contributing to the docs on MDN:


While we have a handful of known bugs around edge cases in the spec that apps are unlikely to hit, and presumably some bugs we're not aware of yet, there are only two deviations from the spec that you need to be aware of:
  • Versioning - Chrome still uses the older db.setVersion() API for versioning, rather than open(name, version) / onupgradeneeded callback now defined in the spec. We're actively working to switch over to the mechanism in the spec, and hope to land that for M22. (Our plan is to maintain the old API as well during a transition period, with console warnings.)
  • Blobs - Chrome does not support storing Blob/File/FileList objects in IDB stores (this support is not mentioned directly in the IDB spec, but rather indirectly by reference to the HTML "structured clone algorithm" which enumerates these types). With Chrome's multiprocess architecture this turns out to be nontrivial to do in an efficient way; we have designs in progress, but no ETA on support. 
We're landing patches like crazy to match the spec, so the closer to Canary you're running the more spec-compliant the implementation should be. We'll continue to send announcement mail here for any breaking changes apps are likely to hit.

Thanks Joshua. I have been following the MDN docs. Though the docs are quite detailed in terms of the spec, I am guessing developers are still apprehensive about browser differences. A few tutorials I looked at earlier were marked with warnings regarding what works and what does not (hello-world style tutorials for Backbone and Ember still use localStorage). For me working with IndexedDB on Chrome has been awesome and am looking forward to the changes.
Reply all
Reply to author
Forward
0 new messages