Skip to content

Instantly share code, notes, and snippets.

@harryi3t
Last active December 20, 2023 06:16
Show Gist options
  • Save harryi3t/d8779d3c0c0c4d41c37fdde81b268fd3 to your computer and use it in GitHub Desktop.
Save harryi3t/d8779d3c0c0c4d41c37fdde81b268fd3 to your computer and use it in GitHub Desktop.
Exports a indexeddb from any website
// Use the latest version of your web-browser
// Tested on chrome 72
// A function to inject scripts in the current webpage
async function injectScript (url) {
return new Promise((resolve) => {
let script = document.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.onload = function(){
resolve();
};
script.src = url;
document.getElementsByTagName('head')[0].appendChild(script);
});
}
// We will be using a promise based library for indexeddb (It's from jake, you can trust it :))
// This will put `idb` in the global scope (window)
await injectScript('https://wzrd.in/standalone/idb')
// If the above does not work you copy the script manually from here
// https://raw.githubusercontent.com/jakearchibald/idb/master/build/idb.js
// To get list of all dbs and their version
let dbs = await window.indexedDB.databases(),
db = dbs[0], // we are exporting the 1st db, change this as per your needs
dbPromise = await idb.openDb(db.name, db.version),
tableNames = [].slice.apply(dbPromise.objectStoreNames);
// Log contents from all the tables
await Promise.all(tableNames.map(async (tableName) => {
return {
[tableName]: await dbPromise.transaction(tableName).objectStore(tableName).getAll()
}
}));
@phamchithanh2
Copy link

Do you have video tutorial.
Thanks a lot

@neogeomat
Copy link

In line 28, it should be openDB instead of openDb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment