I'm new to javascript and i'm currently trying to write an extension that tracks all URLs visited by a user. I'm doing research for a professor, and was told to use indexedDB to track the URLs. I keep getting the following error:
Uncaught NotFoundError: Failed to execute 'transaction' on 'IDBDatabase': One of the specified object stores was not found.
Below is my code:::
let request = window.indexedDB.open("MyTestDatabase", 1),
db,
tx,
store,
index;
request.onerror = function (e) {
console.log("The database 'linkStorage' could not be opened");
};
request.onupgradeneeded = function (e) {
let db = request.result,
store = db.createObjectStore("webpage", { autoIncrement: true }),
index = store.createIndex("link no.", "webpage", { unique: false });
};
request.onsuccess = function (e) {
db = request.result;
tx = db.transaction("webpage", "readwrite");
store = tx.objectStore("URL");
index = store.index("link no.");
db.onerror = function (e) {
console.log("ERROR" + e.target.errorCode);
};
var link = location.href;
store.put(link);
tx.oncomplete = function () {
db.close();
};
};
can someone please help?
You probably created the database without running your onupgradeneeded function. It never created the object store. Try incrementing your version and opening the database again. If the store is still not present, you have not hooked the upgradeneeded event properly.