如何访问 Google Chrome 的 IndexedDB/LevelDB 文件?

How to access Google Chrome's IndexedDB/LevelDB files?

我想使用 Google Chrome 的 IndexedDB 在客户端持久化数据。

想法是稍后通过 Node.JS 访问 chrome 之外的 IndexedDB。 背景是在没有服务器后端的情况下,在本地跟踪使用行为并将收集到的数据存储在客户端以供以后分析的想法。

据我了解,indexedDB 是作为 LevelDB 实现的。但是,我无法使用任何 tools/libs 打开 levelDB,例如 LevelUp/LevelDown or leveldb-json.

我总是收到此错误消息:

leveldb-dump-to-json --file test.json --db https_www.reddit.com_0.indexeddb.leveldb

events.js:141
    throw er; // Unhandled 'error' event
        ^   OpenError: Invalid argument: idb_cmp1 does not match existing   comparator : leveldb.BytewiseComparator
      at /usr/local/lib/node_modules/leveldb-  json/node_modules/levelup/lib/levelup.js:114:34 Christians-Air:IndexedDB 

有人可以帮忙吗?似乎 Chrome 的实现有点像 special/different。

leveldb 中的键是任意二进制序列。客户端实现 comparators to define ordering between keys. The default comparator for leveldb is something equivalent to strncmp. Chrome's comparator for Indexed DB's store is more complicated. If you try and use a leveldb instance with a different comparator than it was created with you'll observe keys in seemingly random order, insertion would be unpredictable or cause corruption - dogs and cats living together, mass hysteria. So leveldb lets you name the comparator (persisted to the database) to help detect and avoid this mistake, which is what you're seeing. Chrome's code names its comparator for Indexed DB "idb_cmp1".

要在 chrome 之外检查 Chrome 的 Indexed DB leveldb 实例之一,您需要实施兼容的比较器。该代码存在于 Chrome 在 content/browser/indexed_db/indexed_db_backing_store.cc 的实现中 - 请注意,不能保证这在各个版本中都是固定的。 (当然,除了向后兼容性)

它已经实施并且 public 现在可以在 github 上使用