Cleanup error: SECURITY_ERR: DOM 18 exception in file: ///android_asset/www/js/DB.js

I use cordova to create a hybrid application for Android and I m using this function that returns a database object, its works perfectly everywhere in the application

    function openDB() {
        var dbUser = null;
        var dBVersion = localStorage.getItem("db_version");
        if (dBVersion == null) {
            try {
                if (!window.openDatabase) {
                    console.log('db init failed');
                } else {
                    dbUser = window.openDatabase("dbname", "1.0.1", "local", 100000);

                }
            } catch(error) {
                console.log(e);
                if (e.name == "INVALID_STATE_ERR") {
                    console.log("Invalid database version.");
                } else {
                    console.log("Unknown error " + e + ".");
                }
            }
        } else {
            dbUser = window.openDatabase("dbname", dBVersion, "local", 100000);
        }
        console.log(dbUser);
        //initialize tables
        if (dbUser != null)
            createTables(dbUser);
        return dbUser;
    }

but when I use a social plugin like facebook and foursquare and return to the application, then my application will not be able to access the database and give an error

Uncaught Error: SECURITY_ERR: DOM Exception 18 at file:///android_asset/www/js/DB.js:27 
dbUser = window.openDatabase("dbname", dBVersion, "local", 100000);

and my application becomes empty because it will not be able to access the database.

+4
source share
1 answer

When do you execute your code?

, , . deviceready, .

 document.addEventListener("deviceready", openDB, false);

, , .

, . 100000 , ?

, .

0

Source: https://habr.com/ru/post/1544269/


All Articles