New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 693726 link

Starred by 1 user

Issue metadata

Status: Fixed
Owner:
Last visit > 30 days ago
Closed: Jan 2018
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: 3
Type: Bug



Sign in to add a comment

DevTools IndexedDB inspector does not show useful values for binary keys

Project Member Reported by jsb...@chromium.org, Feb 17 2017

Issue description

Repro:

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.


 

Comment 1 by jsb...@chromium.org, Feb 17 2017

Screenshot from 2017-02-17 13:17:25.png
16.8 KB View Download
Owner: eostroukhov@chromium.org
Status: Assigned (was: Available)
Cc: cmumford@chromium.org
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?
Cc: eostroukhov@chromium.org
Owner: jsb...@chromium.org

Comment 6 by jsb...@chromium.org, 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.
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

Comment 8 by jsb...@chromium.org, 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




Comment 9 by jsb...@chromium.org, 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





Cc: -eostroukhov@chromium.org
Components: -Blink>Storage>IndexedDB
Labels: -Pri-2 Pri-3
Owner: eostroukhov@chromium.org
Thanks for the explanation. Looks like the issue here is that the DevTools need a better preview for the ArrayBuffer.
Status: Fixed (was: Assigned)
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.
Awesome!

Sign in to add a comment