Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Calculator

0

39
Views
Chrome deleting indexeddb randomly

I am building an application which makes heavy use of indexedDB. I am using code structure as follows:

Base class:

    class BaseDB {
        constructor(options) {
            this.version = options.version;
            this.dbName = options.dbName;
        }
    
        async open() {
            return new Promise((resolve, reject) => {
                let req = indexedDB.open(this.dbName, this.version);
                    req.onsuccess = (e) => {
                        Log(TAG, "open.onsuccess");
                        this.db = req.result
                        resolve(0)
                    };
    
                    req.onerror = (e) => {
                        Log(TAG, "open.onerror");
                        reject(e.target.errorCode);
                    };
    
                    req.onupgradeneeded = (evt) => {
                        this.onUpgrade(evt);
                    };
            })
        }
        //other common methods below ..

    }

Other classes inherit from base class:

    class ConnectionDB extends BaseDB {
        constructor(options) {
            options.dbName = DB_NAME;
            super(options);
            this.store = "connections";
        }
    
        onUpgrade(e) {
            Log(TAG, "open.onupgradeneeded");
            var store = e.currentTarget.result.createObjectStore(
                this.store, { keyPath: 'id', autoIncrement: true });
            store.createIndex(CONNECTION_INDEX, ["name"], { unique: true });
        }

        //other methods below ..
    }

I make use of the classes as follows:

async init() {    
        this.connectionDb = new ConnectionDB({version: 1});
        await this.connectionDb.open();
}

The version is hardcoded at the moment and I have not changed it since the beginning.

Everything works perfectly. But every now and then I find all my indexedDB data gets deleted. This happens only in Chrome and (at least until now) not in other browsers. I noticed that chrome has recently began to ask me to create a "profile". I suspect this problem of indexedDB started happening around the same time, but I am not entirely sure. I want to know if I am doing something wrong in my code, which may cause the db to be deleted in some cases, or is it something to do with Chrome?

7 months ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post job Plans Our process Sales
Legal
Terms and conditions Privacy policy
© 2023 PeakU Inc. All Rights Reserved.