Question

I get the following error when i try to open indexeddb from my firefox extension

[Exception... "Illegal value" nsresult: "0x80070057 (NS_ERROR_ILLEGAL_VALUE)" location: "JS frame :: chrome://extension/abc.html :: openDb :: line 213" data: no]

const DB_NAME = 'dbName';
const DB_VERSION = 1; 
const DB_STORE_NAME = 'dbStore';

var db;

 function openDb() {
  try{
    var req = indexedDB.open(DB_NAME, DB_VERSION);
  req.onsuccess = function (evt) {
    db = this.result;
  };
  req.onerror = function (evt) {
   console.error("openDb:", evt.target.errorCode);
  };

  req.onblocked = function(evt) {
  // If some other tab is loaded with the database, then it needs to be closed
  // before we can proceed.
  console.log("Please close all other tabs with this site open!");
  alert("Please close all other tabs with this site open!");
  };
 }
catch(err){
    alert(err);
}
 }

It goes to the catch part with the above quoted error.

Thanks in advance.

Was it helpful?

Solution

The following should give a working indexedDB

Components.utils.importGlobalProperties(["indexedDB"]);

I tested only if open returns a valid IDBDatabase object. Please confirm data store and retrieve.

(this is just a workaround, indexedDB accessor method is buggy)

edit: Chrome dialogs have a working indexedDB

OTHER TIPS

Update Based on group debugging it's likely you're testing your IDB code in a window-less Firefox environment. Because IDB depends on the window to create it's sandboxed security environment, you cannot run IDB in such an environment.

Interestingly, I'm able to reproduce the Firefox "TypeError: indexedDB is null" @Christoph mentions when using JSFiddle for both prefixed and unprefixed indexedDB interfaces.

Same code, reproduced below, works fine in Chrome. And, strangely, works fine in FF when executed directly from the console

var DB_NAME = 'dbName';
var DB_VERSION = 1;
var DB_STORE_NAME = 'dbStore';

var db;
try {
    var req = self.indexedDB.open(DB_NAME, DB_VERSION);
    req.onsuccess = function (evt) {
        db = this.result;
        console.log('success', evt.target.result);
    };
    req.onerror = function (evt) {
        console.error("error", evt);
    };
    req.onblocked = function (evt) {
        console.log('blocked', evt);
    };
} catch (err) {
    console.error(err.name, err.message);
}

enter image description here

Try running your code in a FF console and see if you can confirm. And in the meantime, I'm curious, in what environment are you seeing this error?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top