Overcoming SecurityError: DOM Exception 18 in PouchDB on Mobile Chrome for iOS-open source projects pouchdb/pouchdb
I am using PouchDB 3.2.1 on a web application targeted for Chrome on iOS. The below error also appears in PouchDB 3.2.0.
When trying to create a connection to a local database on Chrome on iOS, PouchDB uses that browser’s WebSQL database. This, however, fails intermittently with SecurityError: DOM Exception 18 when running the application on both iPhone 5 and iPhone 5s. I have not been able to reproduce this error on my iPad 5 yet.
I am creating a new PouchDB database as follows:
var localDBName = "dbd8008497c6f368d";
self.localPouch = new PouchDB(localDBName, {size: 50});
I have also tried setting size to 49, 1, and 0 and not setting size at all.
Here is a stacktrace sourced from BugSnag:
[native code]:4232 openDatabase
http://192.168.1.144:8000/app/bower_components/pouchdb/dist/pouchdb.js:4232:48 openDB
http://192.168.1.144:8000/app/bower_components/pouchdb/dist/pouchdb.js:4275:18 WebSqlPouch
http://192.168.1.144:8000/app/bower_components/pouchdb/dist/pouchdb.js:5655:40
[native code]:0 Promise
http://192.168.1.144:8000/app/bower_components/pouchdb/dist/pouchdb.js:5570:28 PouchDB
Here is the code near line 4232 of pouchdb.js:
var cachedDatabases = {};
var openDBFunction = (typeof navigator !== 'undefined' &&
navigator.sqlitePlugin &&
navigator.sqlitePlugin.openDatabase) ?
navigator.sqlitePlugin.openDatabase.bind(navigator.sqlitePlugin) :
(typeof sqlitePlugin !== 'undefined' && sqlitePlugin.openDatabase) ?
sqlitePlugin.openDatabase.bind(sqlitePlugin) :
(typeof openDatabase !== 'undefined') ?
openDatabase :
null;
function openDB(name, version, desc, size) {
var db = cachedDatabases[name];
if (!db) {
db = cachedDatabases[name] = openDBFunction(name, version, desc, size);
}
return db;
}
Refreshing the the browser page does not fix the issue. Neither does closing the browser tab and re-opening the page. The only way I can fix the issue is by force-quitting the browser and relaunching the application. However, this is not an acceptable workaround for our users.