yathit / ydn-db

Javascript database module for Indexeddb, Web SQL and localStorage storage mechanisms supporting version migration, advanced query, SQL and transaction.
Apache License 2.0
503 stars 41 forks source link

Unable to work with ydn db in Firefox private browsing mode #107

Open Kauser01 opened 8 years ago

Kauser01 commented 8 years ago

Hi,

I ran into this issue when I was creating/opening ydn-db in Firefox private browsing mode . The error logged in console is InvalidStateError ydn.db-dev.js:257:444

I am using try and catch blocks to catch any error thrown by new ydn.db.Storage but this error is not caught by it.

try { this.db = new ydn.db.Storage("Metadata", schema); } catch (ex) { this.log.error("Unable to initialize IndexedDB/WebSQL", ex); this.db = new ydn.db.Storage("Metadata", schema, { mechanisms: ['sessionstorage', 'memory'] }); }

The same error is reproducible by the ydn-db demo app in Firefox private browsing mode. http://yathit.github.io/ydndb-demo/todo/todo.html The demo app doesn't work as expected.

Note: This happens in normal browsing mode of Firefox also if we set Options -> Privacy -> Firefox will: Never remember history

Is there a way to catch this error or use any other workaround, so that I could resort to session/memory storage model in this situation?

Thanks

mehdirande commented 7 years ago

Hi, I don't think this can be done synchronously, try to do it this way :

  this.db = new ydn.db.Storage("Metadata", schema);
  this.db.addEventListener('fail', function(event) {
    this.log.error("Unable to initialize IndexedDB/WebSQL", ex);
  }, false, this);
winhtaikaung commented 7 years ago

C,z,

yathit commented 7 years ago

The application should work transparently whether privacy mode or not. In privacy mode, data are not saved. This is correctly handled in Chrome, but due to bug 781982, indexedDB opening fail in privacy mode. The good news is they are fixing the issue.

Perhaps, we wait for the bug fix, since workaround will be ugly. For the moment, Chrome incognito mode is working.