9

I have a web-based Android app that uses WebSQL for storage. For some reason, calling openDatabase at one point (in response to a button click), causes a DOMException with the message "SECURITY_ERR: DOM Exception 18".

Note that I am not using PhoneGap.

The main question I'm asking here is: What are the possible causes for a DOMException 18 on openDatabase?

Some more details: This exception only occurs if the database does not exist yet. If it already exists, it works as expected. The function that makes the openDatabase call is used in another part of the app and works just fine.

What I've tried so far:

  • Reducing the size of the database - shouldn't be an issue since it's being created by another part of the app.
  • I've checked the external storage permissions - again, shouldn't be an issue.
  • I read somewhere that the USB cable being plugged in could cause this issue - not what's causing it in this case.

EDIT: This is what the command looks like:

db = openDatabase('my_database', '1.0', 'My database description', 5*1024*1024, function() {});
Goldsmith
  • 508
  • 7
  • 13
  • is that issue solved...i am facing the same issue... – Aravin Jan 09 '14 at 17:09
  • 1
    Never found out what the cause was. In the end, I found WebSQL stability to be too inconsistent on different Android devices/versions for my needs, so I ended up writing a native interface that turned out to be far better. Though I no longer need an answer to this question, I would still be interested in hearing one, for curiosity's sake. – Goldsmith Jan 10 '14 at 10:05
  • i solved this issue..strictly called open database inside the device ready function.... – Aravin Jan 10 '14 at 10:07
  • 1
    Are you using PhoneGap? (just asking to avoid confusion since the original question was non-PhoneGap) – Goldsmith Jan 10 '14 at 10:11

2 Answers2

2

I found that it has to do with the allowed size of the database. If you try to open a db that is larger than 50mb on iOS, you get this error.

ppo
  • 21
  • 3
  • While I wouldn't be surprised if opendatabase causes the exact same error if you go over the size limit, this is not the case here. Like I said, it's successfully created in another part of the app. Also, I've set the limit to 5 MB. – Goldsmith Apr 16 '13 at 08:21
1

According to the spec the spec , it cause by only two

  • The user agent may raise a SECURITY_ERR exception instead of returning a Database object if the request violates a policy decision (e.g. if the user agent is configured to not allow the page to open databases).

  • If origin is not a scheme/host/port tuple, then throw a SECURITY_ERR exception

Kyaw Tun
  • 12,447
  • 10
  • 56
  • 83