Search code examples
iosios5webviewtitaniumtitanium-mobile

SECURITY_ERR: DOM Exception 18 on iOS 5.1 when upgrading app with WebView that opens local database


If you build a simple Titanium mobile application that contains a WebView which has in it javascript that opens a local database, the first time you install it to an iOS 5.1 device it will open the database correctly. However, if you then upgrade the app on the device (it can still be the exact same version/build), it will error when opening the local database:

SECURITY_ERR: DOM Exception 18

Steps to reproduce:

  1. Add the app.js and database.html files below to the root of Resources.
  2. Install app to iOS 5.1 device (Run > iOS Device in Ti Studio).
  3. Open app, it will say "db opened".
  4. Upgrade app on iOS 5.1 device (Run > iOS Device in Ti Studio).
  5. Open app, it will say "db opening failed: Error: SECURITY_ERR: DOM Exception 18".

Here is the code to reproduce:

app.js:

var win = Ti.UI.createWindow({});
var webView = Ti.UI.createWebView({
    top : 0, right : 0, bottom : 0, left : 0, url: 'database.html'
});
win.add(webView);
win.open();

database.html:

<!DOCTYPE HTML>
<html>
    <head>
        <title>db test</title>
        <script>
            window.onload = function () {
                var dbConn;
                try {
                    dbConn = openDatabase('test', '0.1', 'test database', 5 * 1024 * 1024);
                    alert('db opened');
                } catch (e) {
                    alert('db opening failed: ' + e.toString());
                }
            };
        </script> 
    </head>
    <body>
        db test
    </body>
</html>

This issue seems to be the same as Apache Cordova has had and fixed.

https://issues.apache.org/jira/browse/CB-347

Has anyone else run into this issue? Any ideas for a work-around?


Solution

  • We ended up creating a custom webview module for iOS to fix the issue ourselves, as who knows how long it'll take before Titanium does the same:

    Webview Module Source