result read-only property missing from IDBRequest object in Firefox Nightly
Categories
(DevTools :: Console, defect, P3)
Tracking
(Not tracked)
People
(Reporter: ghampton, Unassigned)
References
Details
Steps to reproduce:
In Firefox Nightly 140.0a1
Made a get request to an IndexedDB object store (using IDBObjectStore.get())
Actual results:
The IDBRequest lacked the 'result' read-only property
From the console log:
IDBRequest { error: null, source: IDBObjectStore, transaction: IDBTransaction, readyState: "done", onsuccess: onsuccess(event), onerror: null }
error: null
onerror: null
onsuccess: function onsuccess(event)
readyState: "done"
source: IDBObjectStore { name: "failure", keyPath: (1) […], autoIncrement: false, … }
transaction: IDBTransaction { mode: "readonly", durability: "default", db: IDBDatabase, … }
<prototype>: IDBRequestPrototype { result: Getter, error: Getter, source: Getter, … }
local_store.js:254:25
Expected results:
When I undertake the same request in Firefox Developer Edition the 'result' property is there.
From the console log when run in Developer Edition:
IDBRequest { result: {…}, error: null, source: IDBObjectStore, transaction: IDBTransaction, readyState: "done", onsuccess: onsuccess(event), onerror: null }
error: null
onerror: null
onsuccess: function onsuccess(event)
readyState: "done"
result: Object { establishment: 7, establishment_name: "Test Primary", address_one: "2 Street", … }
source: IDBObjectStore { name: "establishment", keyPath: "establishment", autoIncrement: false, … }
transaction: IDBTransaction { mode: "readonly", durability: "default", db: IDBDatabase, … }
<prototype>: IDBRequestPrototype { result: Getter, error: Getter, source: Getter, … }
local_store.js:254:25
Comment 1•3 months ago
|
||
The Bugbug bot thinks this bug should belong to the 'Core::Storage: IndexedDB' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.
Comment 2•3 months ago
•
|
||
Hey thank you drawing attention to this potential inconsistency. When readyState is "done", it is strange that there is no result and error is none. To pin down the issue, could you try out the following commands in the browser console?
const db = await new Promise((resolve, reject) => { const openReq = indexedDB.open('idb-bug-demo', 1); openReq.onupgradeneeded = e => { const objs = e.target.result.createObjectStore('demo', { keyPath: 'id' }); objs.add({ id: 1, label: 'Hello IndexedDB!' }); }; openReq.onsuccess = e => { resolve(e.target.result); }; openReq.onerror = () => { reject(openReq.error); }; });
const getReq = db.transaction(['demo'], 'readonly').objectStore('demo').get(1);
await new Promise((resolve, reject) => {
getReq.onsuccess = resolve;
getReq.onerror = () => reject(getReq.error);
});
getReq
When I tried them with Nightly 140.0a1, release Firefox 138.0.3 and Chrome 136.0, there always was a result at the end but it could be that to see the issue, one needs to proceed in a different way.
Updated•3 months ago
|
Hi,
When I ran the code you provided it did come back with a 'result' property.
From the console:
IDBRequest { result: {…}, error: null, source: IDBObjectStore, transaction: IDBTransaction, readyState: "done", onsuccess: (), onerror: onerror() }
error: null
onerror: function onerror()
onsuccess: function ()
readyState: "done"
result: Object { id: 1, label: "Hello IndexedDB!" }
source: IDBObjectStore { name: "demo", keyPath: "id", autoIncrement: false, … }
transaction: IDBTransaction { mode: "readonly", durability: "default", db: IDBDatabase, … }
<prototype>: IDBRequestPrototype { result: Getter, error: Getter, source: Getter, … }
The only difference I can see in the way I'm currently accessing is to use callbacks directly (see below example).
let transaction = local_database.transaction('establishment', 'readonly');
let get_request = transaction.objectStore('establishment').get(0);
get_request.onsuccess = event =>
{
let record = event.target.result;
console.debug(event.target);
console.debug(event.target.result);
console.debug(record);
};
Comment 4•3 months ago
|
||
The console UI is devtools logic and there's a lot going on there for processing console API calls and the resulting created grips (with extra context in the debugger API docs, but that's the lower level primitive).
It seems like there may have been some changes in this space, although nothing that jumps out at me (as a non-expert). That said, bug 1958081 seems to have added some interesting and relevant test coverage in https://phabricator.services.mozilla.com/D245074 so maybe :ochameau might have some ideas.
Comment 5•3 months ago
•
|
||
I don't think this is a devtools issue, especially since we do see the result property on the IDBRequest object in jari's example
What it could be is that the record that is being retrieved doesn't exist ? Could you check ghampton?
Because if I'm trying to get something that doesn't exist, it still goes through onsuccess
, but the IDBRequest
object doesn't get a result
property.
You can check with the following code:
var openReq = indexedDB.open('idb-bug-demo', 1);
openReq.onupgradeneeded = e => {
const objs = e.target.result.createObjectStore('demo', {
keyPath: 'id'
});
objs.add({
id: 1,
label: 'Hello IndexedDB!'
});
};
openReq.onsuccess = e => {
const db = e.target.result;
const store = db.transaction(['demo'], 'readonly').objectStore('demo');
const req1 = store.get(1); // "1" is in the store
req1.onsuccess = () => {
console.log("req1.result", req1.result);
}
const req2 = store.get(2); // "2" isn't in the store
req2.onsuccess = () => {
console.log("req2.result", req2.result);
}
};
this outputs:
req1.result Object { id: 1, label: "Hello IndexedDB!" }
req2.result undefined
If the record does exist, then it's something else, and we'd need a functional reduced test case that does highlight the issue
Comment 6•3 months ago
|
||
Yes, that sounds plausible, thanks Nicolas.
Comment 7•3 months ago
|
||
Thanks for the extra investigation, Nicolas.
To clarify, what I mean is that, unless I misunderstood, in comment 0, the example of...
IDBRequest { error: null, source: IDBObjectStore, transaction: IDBTransaction, readyState: "done", onsuccess: onsuccess(event), onerror: null }
...I understand to be something that was displayed to the devtools console, although I was doing some guessing.
If devtools is deciding to hide properties whose values are undefined like JSON does, that's still a devtools policy decision. If we fail to initialize the mozilla::dom::IDBRequest::mResultVal we get the default Value of undefined. The only way we end up doing something else is we can throw but I think devtools may show Invalid Object
in that case?
Being more pedantic, IDBRequest is a WebIDL object and the property is always defined/configured. It's not like we're dynamically building an object.
Comment 8•3 months ago
|
||
Ah okay, I was confused by comment 0, we do miss showing the undefined property, although it does exists (and we should show it).
I'll look into it
Updated•3 months ago
|
(In reply to Nicolas Chevobbe [:nchevobbe] from comment #5)
I don't think this is a devtools issue, especially since we do see the result property on the IDBRequest object in jari's example
What it could be is that the record that is being retrieved doesn't exist ? Could you check ghampton?
Because if I'm trying to get something that doesn't exist, it still goes through
onsuccess
, but theIDBRequest
object doesn't get aresult
property.You can check with the following code:
var openReq = indexedDB.open('idb-bug-demo', 1); openReq.onupgradeneeded = e => { const objs = e.target.result.createObjectStore('demo', { keyPath: 'id' }); objs.add({ id: 1, label: 'Hello IndexedDB!' }); }; openReq.onsuccess = e => { const db = e.target.result; const store = db.transaction(['demo'], 'readonly').objectStore('demo'); const req1 = store.get(1); // "1" is in the store req1.onsuccess = () => { console.log("req1.result", req1.result); } const req2 = store.get(2); // "2" isn't in the store req2.onsuccess = () => { console.log("req2.result", req2.result); } };
this outputs:
req1.result Object { id: 1, label: "Hello IndexedDB!" } req2.result undefined
If the record does exist, then it's something else, and we'd need a functional reduced test case that does highlight the issue
Just to let you know, I ran the above code in Nightly and the output matched your expected example
Description
•