DevTools IndexedDB inspector does not show useful values for binary keys |
||||||
Issue descriptionRepro: 1. Launch chrome with --enable-experimental-web-platform-features 2. Go to a random site (e.g. example.com) and open DevTools. 3. Run this code to create a database indexedDB.deleteDatabase('db'); indexedDB.open('db').onupgradeneeded = e => { const db = e.target.result; const store = db.createObjectStore('store'); store.put('number key', 123); store.put('string key', 'hello'); store.put('date key', new Date()); store.put('array key', [123, 'hello']); store.put('binary key', new Uint8Array([1,2,3])); }; 4. Go to the Application tab of DevTools, drill into IndexedDB > db > store Expected: * All the values in the Key column are useful. Actual: * For the binary key, all that can be seen is 'ArrayBuffer', and when expanded just 'byteLength: (...)' - there's no way to get to the bytes.
,
Dec 11 2017
,
Dec 12 2017
,
Dec 12 2017
I do not seem to be able to access array items when I read the key from the database (using getAllKeys). Joshua, is this something expected?
,
Dec 12 2017
,
Dec 12 2017
Not expected - can you give me an example? Note that arrays `[1,2,3]` and binary data `new Uint8Array([1,2,3])` are different key types, maybe that's confusing things.
,
Dec 12 2017
With this snippet:
=================
const key = new Uint8Array([1,2,3]);
console.log('Key value before instert', key[0])
indexedDB.deleteDatabase('db');
const openDBreq = indexedDB.open('db');
openDBreq.onupgradeneeded = e => {
const db = e.target.result;
const store = db.createObjectStore('store');
store.put('binary key', key);
};
openDBreq.onsuccess = e => {
const keysReq = e.target.result.transaction('store').objectStore('store').getAllKeys();
keysReq.onsuccess = e => {
console.log('Key value read from database', e.target.result[0][0]);
}
}
=========================
Output:
Key value before instert 1
Key value read from database undefined
,
Dec 12 2017
e.target.result[0] will be an ArrayBuffer instance (the 'view' is not used as part of the key, just the data), and ArrayBuffers don't have indexed getters, hence the undefined.
console.log('Key value read from database', e.target.result[0]); // logs the buffer
console.log('Key value read from database', new Uint8Array(e.target.result[0])); // wraps it in a view
,
Dec 12 2017
uh, and then:
console.log('Key value read from database', new Uint8Array(e.target.result[0])[0]); // like [0][0] to actually get the first byte from first key
,
Dec 12 2017
Thanks for the explanation. Looks like the issue here is that the DevTools need a better preview for the ArrayBuffer.
,
Jan 2 2018
DevTools will now preview ArrayBuffer as typed arrays. Synthetic fields were added that show buffer contents as Int8Array/Uint8Array. Buffers with even length can be previewed as Int16Arrays and buffers with length divisible by 4 can be previewed as Int32Arrays.
,
Jan 2 2018
Awesome! |
||||||
►
Sign in to add a comment |
||||||
Comment 1 by jsb...@chromium.org
, Feb 17 201716.8 KB
16.8 KB View Download