Chrome Extensions and Web SQL - DOM Exception 11

Last month I released new version of my extension with some bug fixes and after 3 weeks I checked Google Analytics to see what's the percentage of people who open the extension at least once and wait until the installation is finished (extension has to index large database before it's first lunched).

Now the chart looks like this:

Notice the 3 weeks long period where number of "finishes" is much lower than number of "starts". As I've already mentioned I released new version on 5th August and made small but really critical bug that caused crash after the extension was installed and first lunched.

DOM Exception 11

The exception that caused crash is called DOM Exception 11 and was thrown by openDatabase method.

Unfortunately, this exception is really frustrating because it doesn't give you any hint what's wrong. I tried to google more information but the only thing I found was that other developers are having the same problem.

Solution

After a few hours of try-fail method I found the problem. I was using my own javascript class called Model that opened database connection according to the selected language. What I didn't notice was that I was opening the same database twice even when it wasn't necessary:

  1. after the background page was loaded
  2. when user opened the popup window

I solved this simply by opening the connection just once and then reusing it by Model classes.

The weird thing

The question is: How could I not see it? I use this extension literally every day.

It turned out that this exception is thrown only in one specific situation. To reproduce this problem follow these steps:

  1. Install extension (from Chrome WebStore or an unpacked extension from your computer)
  2. Try to call `openDatabase` on the same database twice
  3. DOM Exception 11 is thrown

But in a little bit different situation:

  1. Install extension (from Chrome WebStore or an unpacked extension from your computer)
  2. Reload the extension in chrome://extensions/ or restart browser
  3. Try to call openDatabase on the same database twice
  4. Everything's fine

The problem is probably that in the first situation Chrome first has to create database files (on your computer) and maybe there's some bug in locks or something... who knows.

Anyway, advice is very simple: Always open database connection just once!

blog comments powered by Disqus