You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

咨询Firefox中获取所有IndexedDB名称的有效方法

How to Get All IndexedDB Database Names Across Chrome and Firefox

Let's break down how to solve this issue, since the approach varies a bit between browsers and versions:

1. Modern Browsers (Chrome ≥47, Firefox ≥108) – Use the Standard API

The window.indexedDB.databases() method is now part of the official IndexedDB spec, but it's asynchronous (returns a Promise) – this might be why you ran into issues if you tried calling it like a synchronous function. Here's the correct usage:

async function fetchAllIndexedDBNames() {
  try {
    // Get the list of databases (returns an array of {name: string, version: number} objects)
    const dbList = await window.indexedDB.databases();
    // Extract just the names
    const dbNames = dbList.map(db => db.name);
    
    console.log("All IndexedDB databases:", dbNames);
    return dbNames;
  } catch (error) {
    console.error("Failed to fetch IndexedDB databases:", error);
    return [];
  }
}

// Call the function
fetchAllIndexedDBNames();

If you're getting the error window.indexedDB.databases() is not a function in Firefox, double-check your browser version – Firefox only added support for this method in version 108. Upgrading your browser should fix this.

2. Older Firefox Versions (<108) – Workarounds

Unfortunately, for older Firefox versions, there's no official, non-privileged way to enumerate all IndexedDB databases from a regular web page. The IndexedDB spec doesn't expose this capability for privacy/security reasons, and the old prefixed methods like webkitdatabases() or mozwebkitdatabases() were long ago deprecated and removed.

Your best options here are:

  • Upgrade Firefox: This is the most straightforward fix, as modern Firefox fully supports the standard databases() method.
  • Track Database Names Locally: If you control the application that creates the IndexedDB databases, store a list of created database names in localStorage or a dedicated "metadata" IndexedDB. For example:
    // When creating a new database
    function createDB(dbName) {
      // Store the name in localStorage
      const existingDBs = JSON.parse(localStorage.getItem("indexedDBList")) || [];
      if (!existingDBs.includes(dbName)) {
        existingDBs.push(dbName);
        localStorage.setItem("indexedDBList", JSON.stringify(existingDBs));
      }
      
      // Proceed with opening the database
      const request = window.indexedDB.open(dbName);
      // ... rest of your DB setup code
    }
    
    // Later, retrieve the list
    function getStoredDBList() {
      return JSON.parse(localStorage.getItem("indexedDBList")) || [];
    }
    

3. Why IDBObjectStore/IDBDatabase Didn't Help

Interfaces like IDBObjectStore and IDBDatabase are for interacting with already opened databases. You need to know the database name upfront to open it, so they can't be used to discover unknown database names.


内容的提问来源于stack exchange,提问作者Rajkumar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 10:22:50