I am trying to open an IndexedDB in Chrome and firefox. My code:
var v = 2;
var request = indexedDB.open("orders", v);
//Firefox code for db init
request.onupgradeneeded = function (e) {
console.log("onupgradeneeded");
var db = e.target.result;
// We can only create Object stores in a setVersion transaction;
if(db.objectStoreNames.contains("client")) {
var storeReq = db.deleteObjectStore("client");
}
const employeeData = [
{ id: "00-01", name: "gopal", age: 35, email: "[email protected]" },
{ id: "00-02", name: "prasad", age: 32, email: "[email protected]" }
];
var objectStore = db.createObjectStore("client", {keyPath: "id"});
for (var i in employeeData) {
objectStore.add(employeeData[i]);
}
}
request.onsuccess = function(e) {
var db = e.target.result;
console.log("Success");
console.log(db);
var transaction = db.transaction(["client"]);
var objectStore = transaction.objectStore("client");
var request = objectStore.get("00-02");
request.onerror = function(event) {
alert("Unable to retrieve daa from database!");
};
request.onsuccess = function(event) {
// Do something with the request.result!
if(request.result) {
alert("Name: " + request.result.name + ", Age: " + request.result.age + ", Email: " + request.result.email);
}
else {
alert("Kenny couldn't be found in your database!");
}
};
};
request.onerror = function(e) {
console.log(e);
};
In Chrome it doesn't work at all. I get an
DOMException: The user denied permission to access the database.
In Firefox it works as shown above. However, when I change the name of the database to, say, myindexeddb
, it doesn't work anymore. I get an UnknownError
.
I have no idea what I am doing wrong.
I am trying to open an IndexedDB in Chrome and firefox. My code:
var v = 2;
var request = indexedDB.open("orders", v);
//Firefox code for db init
request.onupgradeneeded = function (e) {
console.log("onupgradeneeded");
var db = e.target.result;
// We can only create Object stores in a setVersion transaction;
if(db.objectStoreNames.contains("client")) {
var storeReq = db.deleteObjectStore("client");
}
const employeeData = [
{ id: "00-01", name: "gopal", age: 35, email: "[email protected]" },
{ id: "00-02", name: "prasad", age: 32, email: "[email protected]" }
];
var objectStore = db.createObjectStore("client", {keyPath: "id"});
for (var i in employeeData) {
objectStore.add(employeeData[i]);
}
}
request.onsuccess = function(e) {
var db = e.target.result;
console.log("Success");
console.log(db);
var transaction = db.transaction(["client"]);
var objectStore = transaction.objectStore("client");
var request = objectStore.get("00-02");
request.onerror = function(event) {
alert("Unable to retrieve daa from database!");
};
request.onsuccess = function(event) {
// Do something with the request.result!
if(request.result) {
alert("Name: " + request.result.name + ", Age: " + request.result.age + ", Email: " + request.result.email);
}
else {
alert("Kenny couldn't be found in your database!");
}
};
};
request.onerror = function(e) {
console.log(e);
};
In Chrome it doesn't work at all. I get an
DOMException: The user denied permission to access the database.
In Firefox it works as shown above. However, when I change the name of the database to, say, myindexeddb
, it doesn't work anymore. I get an UnknownError
.
I have no idea what I am doing wrong.
Share Improve this question asked Apr 15, 2017 at 9:34 user3813234user3813234 1,6821 gold badge30 silver badges49 bronze badges2 Answers
Reset to default 5In my case, I followed these steps:
- Go to url
chrome://settings/content
in a new Chrome tab - Click
Cookies
- Uncheck
Block third-party cookies
This should resolve the error.
In chrome, go to chrome://settings/content and ensure the top radio button is selected. Also check the Manage Exceptions list to see if that domain is explicitly blocked.