CKTIS / JavaScript
IDBRequest — an IndexedDB operation result
IDBRequest exposes the result or error of an asynchronous IndexedDB operation through events. A successful request does not yet mean that the whole transaction has committed.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
request.result
request.error
request.onsuccess = (event) => { /* read request.result */ };
request.onerror = (event) => { /* read request.error */ };IDBRequest is an EventTarget object returned by IndexedDB operations such as get(). It is not a Promise: simply using await request does not wait for the result. It belongs to Web APIs, not ECMAScript; the presence of Node 24 does not prove browser API availability.
IDBRequest.result contains an operation-specific result; after failure it returns undefined. IDBRequest.error returns a DOMException after failure or null after success. Reading either property while readyState === "pending" throws InvalidStateError. A missing record in get() is a success with an undefined result, not an error.
IDBRequest.onsuccess handles the success event, and IDBRequest.onerror handles error. A request error aborts its associated transaction by default; merely assigning a handler does not change this. Request success does not guarantee commitment: also observe the transaction's complete and abort events.
The example opens a database using IDBOpenDBRequest, a subtype of IDBRequest. The write and read are queued in the same transaction. If get() succeeds, its onsuccess handler logs request.result before the transaction's complete event, if that event fires. The shown output, IndexedDB unavailable: SecurityError, comes from an error path that does not reach the read.
Examples
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>IDBRequest: operation success and transaction completion</title>
</head>
<body>
<h1>Observing an IndexedDB request</h1>
<script>
(() => {
const name = 'cktis-request-' + crypto.getRandomValues(new Uint32Array(4)).join('-');
const report = error => console.log(error.name === 'SecurityError'
? 'IndexedDB unavailable: SecurityError' : `IndexedDB error: ${error.name}`);
let factory, opening;
try {
factory = window.indexedDB;
if (!factory) {
console.log('IndexedDB unavailable: API missing');
return;
}
opening = factory.open(name, 1);
} catch (error) {
report(error);
return;
}
let created = false;
opening.onerror = () => report(opening.error);
opening.onupgradeneeded = () => {
created = true;
opening.result.createObjectStore('values');
};
opening.onsuccess = () => {
const db = opening.result;
if (!created) {
db.close();
console.log('Fixture name already in use');
return;
}
const tx = db.transaction('values', 'readwrite');
const store = tx.objectStore('values');
store.put('circle', 'shape');
const request = store.get('shape');
const cleanup = () => {
db.close();
factory.deleteDatabase(name);
};
console.log(`get before events: ${request.readyState}`);
request.onsuccess = () => {
console.log(`get success: ${request.readyState}, value: ${request.result}`);
};
request.onerror = () => console.log(`get error: ${request.error.name}`);
tx.oncomplete = event => {
console.log(`transaction: ${event.type}`);
cleanup();
};
tx.onabort = event => {
console.log(`transaction: ${event.type}`);
cleanup();
};
};
})();
</script>
</body>
</html>Result
IndexedDB unavailable: SecurityError
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.