[TIMOB-12466] iOS: SECURITY_ERR: DOM Exception 18 on iOS 5.1 when upgrading app with WebView that opens local database
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | Low |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | iOS |
Labels | ios, opendatabase, webview |
Reporter | Justin Toth |
Assignee | Unknown |
Created | 2013-01-18T06:53:28.000+0000 |
Updated | 2018-02-28T20:03:51.000+0000 |
Description
Summary of issue:
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, maybe you can learn something from how they fixed it...
https://issues.apache.org/jira/browse/CB-347
This is a serious issue for my company because we have a Sencha Touch app that is integrated into our Titanium app "hub" within a webview, so basically we can't support iOS 5 devices without a fix for this.
We created a native iOS module that fixes the bug, using the same approach that Cordova implemented. It is very straightforward, I suggest that you guys add this to the standard Titanium WebView ASAP. Source code can be found at the link below: https://bitbucket.org/justintoth/titanium_modules/src/3fa1d1c3f8befbf077145eb8657c87a8b274a7a4/webview/iphone/Classes/TiWebviewModule.m?at=master