TypeError: indexedDB.databases 不是函数

问题描述 投票:0回答:1

此脚本打印 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)));
javascript indexeddb
1个回答
0
投票

indexedDb.databases() 方法仅支持部分浏览器。 请查看下表以了解它。

© www.soinside.com 2019 - 2024. All rights reserved.