我想使用Google Chrome的IndexedDB在客户端保留数据 .
想法是稍后通过Node.JS访问chrome之外的IndexedDB . 背景是在本地跟踪使用行为并将收集的数据存储在客户端上以供以后分析而无需服务器后端的想法 .
根据我的理解,indexedDB是作为LevelDB实现的 . 但是,我无法使用LevelUp / LevelDown或leveldb-json等任何工具/库打开levelDB .
我总是收到此错误消息:
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实现在某种程度上是特殊/不同的 .
1 回答
leveldb中的键是任意二进制序列 . 客户端实现comparators以定义密钥之间的排序 . leveldb的default comparator等同于
strncmp
. Chrome 's comparator for Indexed DB'的商店更复杂 . 如果您尝试使用leveldb实例,并使用与您创建的比较不同的比较器'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' . 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中的实现中 - 请注意,不能保证在各版本中修复此问题 . (当然,除了向后兼容性)