javascript - TypeError:indexedDB.databases 不是函数
问题描述
此脚本打印 IndexedDB 的内容。
当我在网站控制台中运行此脚本时,它会显示:
我尝试使用 IDBDatabase(),但它说“非法构造函数”。
你能指出我的错误吗?
这是代码:
const dumpIndexedDB = (dbName) => {
const DB_VERSION = 1;
const req = indexedDB.open(dbName, DB_VERSION);
req.onsuccess = function () {
const db = req.result;
const objectStoreNames = db.objectStoreNames || [];
console.log(`[*] Database: ${dbName}`);
Array.from(objectStoreNames).forEach((storeName) => {
const txn = db.transaction(storeName, "readonly");
const objectStore = txn.objectStore(storeName);
console.log(`\t[+] ObjectStore: ${storeName}`);
// Print all entries in objectStore with name `storeName`
objectStore.getAll().onsuccess = (event) => {
const items = event.target.result || [];
items.forEach((item) => console.log(`\t\t[-] `, item));
};
});
};
};
indexedDB
.databases()
.then((dbs) => dbs.forEach((db) => dumpIndexedDB(db.name)));
解决方案
推荐阅读
- c# - 如何在 C# 中运行可变数量的并发参数化无限循环类型的线程?
- java - 如何覆盖地图中的 toString ...?
- visual-studio-code - 如何在vs中为一行代码创建快捷方式?
- javascript - 类型错误:client.commands.get(...).execute 不是函数
- python - Python 3 没有升级 pip。我是否链接了错误的目录?
- python-3.x - 通过 Google Calendar API 创建事件 - 授权问题
- javascript - 消息传递和 Firebase 托管中的 Firebase Service Worker 错误
- javascript - 如何在模态中显示来自 v-for 的单击元素的 vue 数据
- sql-server - DB2 中的@@error 有什么相同之处?
- python - 如何在使用 MongoDB 更改拉取新数据时实时更新图表?