I'm new to indexedDB and my goal is to create a chrome extension that keeps track of all SSO pages and their redirects. My idea is to store each sign-in link and their respective redirects in a tree; however, indexedDB creates a new database for each link that i visit, so i'm having trouble making the tree. Is there any way around this?
'''
// Record variables to be used for indexedDB
let request = window.indexedDB.open("MyTestDatabase", 2),
db,
tx,
store,
index;
// triggered when a database of a bigger version number than the existing stored database is loaded
request.onupgradeneeded = function (e) {
let db = request.result,
store = db.createObjectStore("URL", { autoIncrement: true }),
index = store.createIndex("link no.", "URL", { unique: false });
};
// triggered if the database cannot load
request.onerror = function (e) {
console.log("The database 'linkStorage' could not be opened");
};
/* triggered if it does load
- open a transaction, define the object store ("URL")
- creates an index for data retrieval
- append the current link to indexedDB, console.log it, and print the index
*/
request.onsuccess = function (e) {
db = request.result;
(tx = db.transaction("URL", "readwrite")),
(store = tx.objectStore("URL")),
store.index("link no.");
db.onerror = function (e) {
console.log("ERROR could not open db" + e.target.errorCode);
};
var link = window.location.href;
store.put(link);
var countRequest = store.count();
countRequest.onsuccess = function () {
var count = countRequest.result;
var lastLink = store.get(count);
lastLink.onsuccess = function () {
console.log("Index = " + count);
console.log("Current link = " + lastLink.result);
};
};
tx.oncomplete = function () {
db.close();
};
};
'''