node.js - 如何访问 Google Chrome 的 IndexedDB/LevelDB 文件?

标签 node.js google-chrome indexeddb leveldb levelup

我想使用 Google Chrome 的 IndexedDB 在客户端保存数据。

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

据我了解,indexedDB 是作为 LevelDB 实现的。但是,我无法使用任何工具/库(如 LevelUp)打开 levelDB。/LevelDownleveldb-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 的实现似乎有些特殊/不同。

最佳答案

leveldb 中的键是任意二进制序列。客户实现comparators定义键之间的顺序。 default comparator for leveldb 相当于 strncmp。 Chrome 的 Indexed DB 存储比较器更复杂。如果您尝试使用具有与创建时不同的比较器的 leveldb 实例,您将观察到看似随机顺序的键,插入将是不可预测的或导致损坏 - 狗和猫生活在一起,集体歇斯底里。所以 leveldb 让你命名比较器(持久化到数据库)来帮助检测和避免这个错误,这就是你所看到的。 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 的实现中 - 请注意,不能保证跨版本修复此问题。 (当然除了向后兼容)

关于node.js - 如何访问 Google Chrome 的 IndexedDB/LevelDB 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35074659/

相关文章:

node.js - 如何查看已启动的 Node.js 变量?

javascript - 处理字符串中相同出现的字符

javascript - indexedDB openCursor 事务成功返回空数组

javascript - 如何使用 IndexedDB objectStore 中的值自动填充选择框?

javascript - 找出 Heroku 应用程序的问题所在

javascript - 如何使用 mongo/mongoose 通过 _id 以外的字段查找文档

plugins - 如何检查 Chrome 插件源代码?

jQuery 在选择中添加许多选项会杀死 chrome

javascript - 使用前端路由防止 iOS chrome 状态栏重新出现

javascript - IndexedDB “and” 和 “or” 查询