Indexed Database API 3.0

W3C Working Draft, 7 November 2024

More details about this documentThis version: https://www.w3.org/TR/2024/WD-IndexedDB-3-20241107/Latest published version: https://www.w3.org/TR/IndexedDB/Editor's Draft: https://w3c.github.io/IndexedDB/Previous Versions: https://www.w3.org/TR/2024/WD-IndexedDB-3-20241015/https://www.w3.org/TR/2024/WD-IndexedDB-3-20241015/History: https://www.w3.org/standards/history/IndexedDB-3/Test Suite: https://github.com/web-platform-tests/wpt/tree/master/IndexedDBFeedback: GitHubEditor: Joshua Bell (Google) Former Editor: Ali Alabbas (Formerly of Microsoft) Copyright © 2024 World Wide Web Consortium. W3C®liability, trademark and permissive document license rules apply.

This document defines APIs for a database of records holding simple values and hierarchical objects. Each record consists of a key and some value. Moreover, the database maintains indexes over records it stores. An application developer directly uses an API to locate records either by their key or by using an index. A query language can be layered on this API. An indexed database can be implemented using a persistent B-tree data structure.

This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.

This document was published by the Web Applications Working Group as a Working Draft. This document is intended to become a W3C Recommendation.

This document was published by the Web Applications Working Group as a Working Draft using the Recommendation track. Feedback and comments on this specification are welcome. Please use GitHub issues Historical discussions can be found in the [email protected] archives.

Publication as a Working Draft does not imply endorsement by W3C and its Members. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

This document is governed by the 03 November 2023 W3C Process Document.

This is the Third Edition of Indexed Database API. The First Edition, simply titled “Indexed Database API”, became a W3C Recommendation on 8 January 2015. The Second Edition, titled “Indexed Database API 2.0”, became a W3C Recommendation on 30 January 2018.

Indexed Database API 3.0 is intended to supersede Indexed Database API 2.0.

1. Introduction

User agents need to store large numbers of objects locally in order to satisfy off-line data requirements of Web applications. WEBSTORAGE is useful for storing pairs of keys and their corresponding values. However, it does not provide in-order retrieval of keys, efficient searching over values, or storage of duplicate values for a key.

This specification provides a concrete API to perform advanced key-value data management that is at the heart of most sophisticated query processors. It does so by using transactional databases to store keys and their corresponding values (one or more per key), and providing a means of traversing keys in a deterministic order. This is often implemented through the use of persistent B-tree data structures that are considered efficient for insertion and deletion as well as in-order traversal of very large numbers of data records.

The following example uses the API to access a “library” database. It has a “books” object store that holds books records stored by their “isbn” property as the primary key. Book records have a “title” property. This example artificially requires that book titles are unique. The code enforces this by creating an index named “by_title” with the unique option set. This index is used to look up books by title, and will prevent adding books with non-unique titles.

Book records also have an “author” property, which is not required to be unique. The code creates another index named “by_author” to allow look-ups by this property.

The code first opens a connection to the database. The upgradeneeded event handler code creates the object store and indexes, if needed. The success event handler code saves the opened connection for use in later examples.

const request = indexedDB.open(“library”);let db; request.onupgradeneeded =function(){// The database did not previously exist, so create object stores and indexes.const db = request.result;const store = db.createObjectStore(“books”,{keyPath:“isbn”});const titleIndex = store.createIndex(“by_title”,“title”,{unique:true});const authorIndex = store.createIndex(“by_author”,“author”);// Populate with initial data. store.put({title:“Quarry Memories”, author:“Fred”, isbn:123456}); store.put({title:“Water Buffaloes”, author:“Fred”, isbn:234567}); store.put({title:“Bedrock Nights”, author:“Barney”, isbn:345678});}; request.onsuccess =function(){ db = request.result;};The following example populates the database using a transaction.

const tx = db.transaction(“books”,“readwrite”);const store = tx.objectStore(“books”); store.put({title:“Quarry Memories”, author:“Fred”, isbn:123456}); store.put({title:“Water Buffaloes”, author:“Fred”, isbn:234567}); store.put({title:“Bedrock Nights”, author:“Barney”, isbn:345678}); tx.oncomplete =function(){// All requests have succeeded and the transaction has committed.};The following example looks up a single book in the database by title using an index.

const tx = db.transaction(“books”,“readonly”);const store = tx.objectStore(“books”);const index = store.index(“by_title”);const request = index.get(“Bedrock Nights”); request.onsuccess =function(){const matching = request.result;if(matching !==undefined){// A match was found. report(matching.isbn, matching.title, matching.author);}else{// No match was found. report(null);}};The following example looks up all books in the database by author using an index and a cursor.

const tx = db.transaction(“books”,“readonly”);const store = tx.objectStore(“books”);const index = store.index(“by_author”);const request = index.openCursor(IDBKeyRange.only(“Fred”)); request.onsuccess =function(){const cursor = request.result;if(cursor){// Called for each matching record. report(cursor.value.isbn, cursor.value.title, cursor.value.author); cursor.continue();}else{// No more matching records. report(null);}};The following example shows one way to handle errors when a request fails.

const tx = db.transaction(“books”,“readwrite”);const store = tx.objectStore(“books”);const request = store.put({title:“Water Buffaloes”, author:“Slate”, isbn:987654}); request.onerror =function(event){// The uniqueness constraint of the “by_title” index failed. report(request.error);// Could call event.preventDefault() to prevent the transaction from aborting.}; tx.onabort =function(){// Otherwise the transaction will automatically abort due the failed request. report(tx.error);};The database connection can be closed when it is no longer needed.

db.close();In the future, the database might have grown to contain other object stores and indexes. The following example shows one way to handle migrating from an older version.

const request = indexedDB.open(“library”,3);// Request version 3.let db; request.onupgradeneeded =function(event){const db = request.result;if(event.oldVersion <1){// Version 1 is the first version of the database.const store = db.createObjectStore(“books”,{keyPath:“isbn”});const titleIndex = store.createIndex(“by_title”,“title”,{unique:true});const authorIndex = store.createIndex(“by_author”,“author”);}if(event.oldVersion <2){// Version 2 introduces a new index of books by year.const bookStore = request.transaction.objectStore(“books”);const yearIndex = bookStore.createIndex(“by_year”,“year”);}if(event.oldVersion <3){// Version 3 introduces a new object store for magazines with two indexes.const magazines = db.createObjectStore(“magazines”);const publisherIndex = magazines.createIndex(“by_publisher”,“publisher”);const frequencyIndex = magazines.createIndex(“by_frequency”,“frequency”);}}; request.onsuccess =function(){ db = request.result;// db.version will be 3.}; A single database can be used by multiple clients (pages and workers) simultaneously — transactions ensure they don’t clash while reading and writing. If a new client wants to upgrade the database (via the upgradeneeded event), it cannot do so until all other clients close their connection to the current version of the database. To avoid blocking a new client from upgrading, clients can listen for the versionchange event. This fires when another client is wanting to upgrade the database. To allow this to continue, react to the versionchange event by doing something that ultimately closes this client’s connection to the database.

One way of doing this is to reload the page:

db.onversionchange =function(){// First, save any unsaved data: saveUnsavedData().then(function(){// If the document isn’t being actively used, it could be appropriate to reload// the page without the user’s interaction.if(!document.hasFocus()){ location.reload();// Reloading will close the database, and also reload with the new JavaScript// and database definitions.}else{// If the document has focus, it can be too disruptive to reload the page.// Maybe ask the user to do it manually: displayMessage(“Please reload this page for the latest version.”);}});};function saveUnsavedData(){// How you do this depends on your app.}function displayMessage(){// Show a non-modal message to the user.}Another way is to call the connection’s close() method. However, you need to make sure your app is aware of this, as subsequent attempts to access the database will fail.

db.onversionchange =function(){ saveUnsavedData().then(function(){ db.close(); stopUsingTheDatabase();});};function stopUsingTheDatabase(){// Put the app into a state where it no longer uses the database.}The new client (the one attempting the upgrade) can use the blocked event to detect if other clients are preventing the upgrade from happening. The blocked event fires if other clients still hold a connection to the database after their versionchange events have fired.

const request = indexedDB.open(“library”,4);// Request version 4.let blockedTimeout; request.onblocked =function(){// Give the other clients time to save data asynchronously. blockedTimeout = setTimeout(function(){ displayMessage(“Upgrade blocked - Please close other tabs displaying this site.”);},1000);}; request.onupgradeneeded =function(event){ clearTimeout(blockedTimeout); hideMessage();// …};function hideMessage(){// Hide a previously displayed message.}The user will only see the above message if another client fails to disconnect from the database. Ideally the user will never see this.

2. Constructs

A name is a string equivalent to a DOMString; that is, an arbitrary sequence of 16-bit code units of any length, including the empty string. Names are always compared as opaque sequences of 16-bit code units.

NOTE: As a result, name comparison is sensitive to variations in case as well as other minor variations such as normalization form, the inclusion or omission of controls, and other variations in Unicode text. Charmod-NormIf an implementation uses a storage mechanism which does not support arbitrary strings, the implementation can use an escaping mechanism or something similar to map the provided name to a string that it can store.

To create a sorted name list from a listnames, run these steps:

  1. Let sorted be namessorted in ascending order with the code unit less than algorithm.
  2. Return a new DOMStringList associated with sorted. Details This matches the sort() method on an Array of String. This ordering compares the 16-bit code units in each string, producing a highly efficient, consistent, and deterministic sort order. The resulting list will not match any particular alphabet or lexicographical order, particularly for code points represented by a surrogate pair.

2.1. Database

Each storage key has an associated set of databases. A database has zero or more object stores which hold the data stored in the database.

A database has a name which identifies it within a specific storage key. The name is a name, and stays constant for the lifetime of the database.

A database has a version. When a database is first created, its version is 0 (zero).

NOTE: Each database has one version at a time; a database can’t exist in multiple versions at once. The only way to change the version is using an upgrade transaction.

A database has at most one associated upgrade transaction, which is either null or an upgrade transaction, and is initially null.

2.1.1. Database connection

Script does not interact with databases directly. Instead, script has indirect access via a connection. A connection object can be used to manipulate the objects of that database. It is also the only way to obtain a transaction for that database.

The act of opening a database creates a connection. There may be multiple connections to a given database at any given time.

A connection can only access databases associated with the storage key of the global scope from which the connection is opened.

NOTE: This is not affected by changes to the Document’s domain.

A connection has a version, which is set when the connection is created. It remains constant for the lifetime of the connection unless an upgrade is aborted, in which case it is set to the previous version of the database. Once the connection is closed the version does not change.

Each connection has a close pending flag which is initially false.

When a connection is initially created it is in an opened state. The connection can be closed through several means. If the execution context where the connection was created is destroyed (for example due to the user navigating away from that page), the connection is closed. The connection can also be closed explicitly using the steps to close a database connection. When the connection is closed its close pending flag is always set to true if it hasn’t already been.

A connection may be closed by a user agent in exceptional circumstances, for example due to loss of access to the file system, a permission change, or clearing of the storage key’s storage. If this occurs the user agent must run close a database connection with the connection and with the forced flag set to true.

A connection has an object store set, which is initialized to the set of object stores in the associated database when the connection is created. The contents of the set will remain constant except when an upgrade transaction is live.

A connection’s get the parent algorithm returns null.

An event with type versionchange will be fired at an open connection if an attempt is made to upgrade or delete the database. This gives the connection the opportunity to close to allow the upgrade or delete to proceed.

An event with type close will be fired at a connection if the connection is closed abnormally.

2.2. Object store

An object store is the primary storage mechanism for storing data in a database.

Each database has a set of object stores. The set of object stores can be changed, but only using an upgrade transaction, i.e. in response to an upgradeneeded event. When a new database is created it doesn’t contain any object stores.

An object store has a list of records which hold the data stored in the object store. Each record consists of a key and a value. The list is sorted according to key in ascending order. There can never be multiple records in a given object store with the same key.

An object store has a name, which is a name. At any one time, the name is unique within the database to which it belongs.

An object store optionally has a key path. If the object store has a key path it is said to use in-line keys. Otherwise it is said to use out-of-line keys.

An object store optionally has a key generator.

An object store can derive a key for a record from one of three sources:

  1. A key generator. A key generator generates a monotonically increasing numbers every time a key is needed.
  2. Keys can be derived via a key path.
  3. Keys can also be explicitly specified when a value is stored in the object store.

2.2.1. Object store handle

Script does not interact with object stores directly. Instead, within a transaction, script has indirect access via an object store handle.

An object store handle has an associated object store and an associated transaction. Multiple handles may be associated with the same object store in different transactions, but there must be only one object store handle associated with a particular object store within a transaction.

An object store handle has an index set, which is initialized to the set of indexes that reference the associated object store when the object store handle is created. The contents of the set will remain constant except when an upgrade transaction is live.

An object store handle has a name, which is initialized to the name of the associated object store when the object store handle is created. The name will remain constant except when an upgrade transaction is live.

2.3. Values

Each record is associated with a value. User agents must support any serializable object. This includes simple types such as String primitive values and Date objects as well as Object and Array instances, File objects, Blob objects, ImageData objects, and so on. Record values are stored and retrieved by value rather than by reference; later changes to a value have no effect on the record stored in the database.

Record values are Records output by the StructuredSerializeForStorage operation.

2.4. Keys

In order to efficiently retrieve records stored in an indexed database, each record is organized according to its key.

A key has an associated type which is one of: number, date, string, binary, or array.

A key also has an associated value, which will be either: an unrestricted double if type is number or date, a DOMString if type is string, a byte sequence if type is binary, or a list of other keys if type is array.

An ECMAScript ECMA-262 value can be converted to a key by following the steps to convert a value to a key.

NOTE: The following ECMAScript types are valid keys: - Number primitive values, except NaN. This includes Infinity and -Infinity.

  • Date objects, except where the DateValue internal slot is NaN.
  • String primitive values.
  • ArrayBuffer objects (or views on buffers such as Uint8Array).
  • Array objects, where every item is defined, is itself a valid key, and does not directly or indirectly contain itself. This includes empty arrays. Arrays can contain other arrays.

Attempting to convert other ECMAScript values to a key will fail.

An array key is a key with typearray. The subkeys of an array key are the items of the array key’s value.

To compare two keysa and b, run these steps:

  1. Let ta be the type of a.
  2. Let tb be the type of b.
  3. If ta does not equal tb, then run these steps:
  4. If ta is array, then return 1.
  5. If tb is array, then return -1.
  6. If ta is binary, then return 1.
  7. If tb is binary, then return -1.
  8. If ta is string, then return 1.
  9. If tb is string, then return -1.
  10. If ta is date, then return 1.
  11. Assert: tb is date.
  12. Return -1.
  13. Let va be the value of a.
  14. Let vb be the value of b.
  15. Switch on ta:

numberdate 120. If va is greater than vb, then return 1. 121. If va is less than vb, then return -1. 122. Return 0. string124. If va is code unit less thanvb, then return -1. 125. If vb is code unit less thanva, then return 1. 126. Return 0. binary128. If va is byte less thanvb, then return -1. 129. If vb is byte less thanva, then return 1. 130. Return 0. array132. Let length be the lesser of va’s size and vb’s size. 133. Let i be 0. 134. While i is less than length, then: 135. Let c be the result of recursively comparing two keys with vai and vbi. 136. If c is not 0, return c. 137. Increase i by 1. 138. If va’s size is greater than vb’s size, then return 1. 139. If va’s size is less than vb’s size, then return -1. 140. Return 0. The keya is greater than the keyb if the result of comparing two keys with a and b is 1.

The keya is less than the keyb if the result of comparing two keys with a and b is -1.

The keya is equal to the keyb if the result of comparing two keys with a and b is 0.

NOTE: As a result of the above rules, negative infinity is the lowest possible value for a key. Number keys are less than date keys. Date keys are less than string keys. String keys are less than binary keys. Binary keys are less than array keys. There is no highest possible key value. This is because an array of any candidate highest key followed by another key is even higher.

NOTE: Members of binary keys are compared as unsigned byte values (in the range 0 to 255 inclusive) rather than signed byte values (in the range -128 to 127 inclusive).

2.5. Key path

A key path is a string or list of strings that defines how to extract a key from a value. A valid key path is one of:

  • An empty string.
  • An identifier, which is a string matching the IdentifierName production from the ECMAScript Language Specification ECMA-262.
  • A string consisting of two or more identifiers separated by periods (U+002E FULL STOP).
  • A non-empty list containing only strings conforming to the above requirements.

NOTE: Spaces are not allowed within a key path.

Key path values can only be accessed from properties explicitly copied by StructuredSerializeForStorage, as well as the following type-specific properties:

Type Properties
Blob size, type
File name, lastModified
Array length
String length

2.6. Index

It is sometimes useful to retrieve records in an object store through other means than their key. An index allows looking up records in an object store using properties of the values in the object storesrecords.

An index is a specialized persistent key-value storage and has a referencedobject store. The index has a list of records which hold the data stored in the index. The records in an index are automatically populated whenever records in the referenced object store are inserted, updated or deleted. There can be several indexes referencing the same object store, in which changes to the object store cause all such indexes to get updated.

The values in the index’s records are always values of keys in the index’s referenced object store. The keys are derived from the referenced object store’s values using a key path. If a given record with key X in the object store referenced by the index has the value A, and evaluating the index’s key path on A yields the result Y, then the index will contain a record with key Y and value X.

For example, if an index’s referenced object store contains a record with the key 123 and the value { name: “Alice”, title: “CEO” }, and the index’s key path is “name” then the index would contain a record with the key “Alice” and the value 123. Records in an index are said to have a referenced value. This is the value of the record in the index’s referenced object store which has a key equal to the index’s record’s value. So in the example above, the record in the index whose key is Y and value is X has a referenced value of A.

In the preceding example, the record in the index with key “Alice” and value 123 would have a referenced value of { name: “Alice”, title: “CEO” }. NOTE: Each record in an index references one and only one record in the index’s referenced object store. However there can be multiple records in an index which reference the same record in the object store. And there can also be no records in an index which reference a given record in an object store.

The records in an index are always sorted according to the record’s key. However unlike object stores, a given index can contain multiple records with the same key. Such records are additionally sorted according to the index’s record’s value (meaning the key of the record in the referenced object store).

An index has a name, which is a name. At any one time, the name is unique within index’s referencedobject store.

An index has a unique flag. When true, the index enforces that no two records in the index has the same key. If a record in the index’s referenced object store is attempted to be inserted or modified such that evaluating the index’s key path on the records new value yields a result which already exists in the index, then the attempted modification to the object store fails.

An index has a multiEntry flag. This flag affects how the index behaves when the result of evaluating the index’s key path yields an array key. If its multiEntry flag is false, then a single record whose key is an array key is added to the index. If its multiEntry flag is true, then one record is added to the index for each of the subkeys.

2.6.1. Index handle

Script does not interact with indexes directly. Instead, within a transaction, script has indirect access via an index handle.

An index handle has an associated index and an associated object store handle. The transaction of an index handle is the transaction of its associated object store handle. Multiple handles may be associated with the same index in different transactions, but there must be only one index handle associated with a particular index within a transaction.

An index handle has a name, which is initialized to the name of the associated index when the index handle is created. The name will remain constant except when an upgrade transaction is live.

2.7. Transactions

A transaction is used to interact with the data in a database. Whenever data is read or written to the database it is done by using a transaction.

Transactions offer some protection from application and system failures. A transaction may be used to store multiple data records or to conditionally modify certain data records. A transaction represents an atomic and durable set of data access and data mutation operations.

All transactions are created through a connection, which is the transaction’s connection.

A transaction has a scope which is a set of object stores that the transaction may interact with.

NOTE: A transaction’s scope remains fixed unless the transaction is an upgrade transaction.

Two transactions have overlapping scope if any object store is in both transactions’ scope.

A transaction has a mode that determines which types of interactions can be performed upon that transaction. The mode is set when the transaction is created and remains fixed for the life of the transaction. A transaction’s mode is one of the following:

“readonly” The transaction is only allowed to read data. No modifications can be done by this type of transaction. This has the advantage that several read-only transactions can be started at the same time even if their scopes are overlapping, i.e. if they are using the same object stores. This type of transaction can be created any time once a database has been opened.

“readwrite” The transaction is allowed to read, modify and delete data from existing object stores. However object stores and indexes can’t be added or removed. Multiple “readwrite” transactions can’t be started at the same time if their scopes are overlapping since that would mean that they can modify each other’s data in the middle of the transaction. This type of transaction can be created any time once a database has been opened.

“versionchange” The transaction is allowed to read, modify and delete data from existing object stores, and can also create and remove object stores and indexes. It is the only type of transaction that can do so. This type of transaction can’t be manually created, but instead is created automatically when an upgradeneeded event is fired.

A transaction has a durability hint. This is a hint to the user agent of whether to prioritize performance or durability when committing the transaction. The durability hint is one of the following:

“strict” The user agent may consider that the transaction has successfully committed only after verifying that all outstanding changes have been successfully written to a persistent storage medium.

“relaxed” The user agent may consider that the transaction has successfully committed as soon as all outstanding changes have been written to the operating system, without subsequent verification.

“default” The user agent should use its default durability behavior for the storage bucket. This is the default for transactions if not otherwise specified.

NOTE: In a typical implementation, “strict” is a hint to the user agent to flush any operating system I/O buffers before a complete event is fired. While this provides greater confidence that the changes will be persisted in case of subsequent operating system crash or power loss, flushing buffers can take significant time and consume battery life on portable devices. Web applications are encouraged to use “relaxed” for ephemeral data such as caches or quickly changing records, and “strict” in cases where reducing the risk of data loss outweighs the impact to performance and power. Implementations are encouraged to weigh the durability hint from applications against the impact to users and devices.

A transaction optionally has a cleanup event loop which is an event loop.

A transaction has a request list of pending requests which have been made against the transaction.

A transaction has a error which is set if the transaction is aborted.

A transaction’s get the parent algorithm returns the transaction’s connection.

A read-only transaction is a transaction with mode “readonly”.

A read/write transaction is a transaction with mode “readwrite”.

2.7.1. Transaction lifecycle

A transaction has a state, which is one of the following:

activeA transaction is in this state when it is first created, and during dispatch of an event from a request associated with the transaction.

New requests can be made against the transaction when it is in this state.

inactiveA transaction is in this state after control returns to the event loop after its creation, and when events are not being dispatched.

No requests can be made against the transaction when it is in this state.

committingOnce all requests associated with a transaction have completed, the transaction will enter this state as it attempts to commit.

No requests can be made against the transaction when it is in this state.

finishedOnce a transaction has committed or aborted, it enters this state.

No requests can be made against the transaction when it is in this state.

Transactions are expected to be short lived. This is encouraged by the automatic committing functionality described below.

NOTE: Authors can still cause transactions to stay alive for a long time; however, this usage pattern is not advised as it can lead to a poor user experience.

The lifetime of a transaction is as follows:

  1. A transaction is created with a scope and a mode. When a transaction is created its state is initially active.
  2. When an implementation is able to enforce the constraints for the transaction’s scope and mode, defined below, the implementation must queue a task to start the transaction asynchronously.

Once the transaction has been started the implementation can begin executing the requests placed against the transaction. Requests must be executed in the order in which they were made against the transaction. Likewise, their results must be returned in the order the requests were placed against a specific transaction. There is no guarantee about the order that results from requests in different transactions are returned.

NOTE: Transaction modes ensure that two requests placed against different transactions can execute in any order without affecting what resulting data is stored in the database. 217. When each request associated with a transaction is processed, a success or errorevent will be fired. While the event is being dispatched, the transaction state is set to active, allowing additional requests to be made against the transaction. Once the event dispatch is complete, the transaction’s state is set to inactive again. 218. A transaction can be aborted at any time before it is finished, even if the transaction isn’t currently active or hasn’t yet started.

An explicit call to abort() will initiate an abort. An abort will also be initiated following a failed request that is not handled by script.

When a transaction is aborted the implementation must undo (roll back) any changes that were made to the database during that transaction. This includes both changes to the contents of object stores as well as additions and removals of object stores and indexes. 219. The implementation must attempt to commit a transaction when all requests placed against the transaction have completed and their returned results handled, no new requests have been placed against the transaction, and the transaction has not been aborted

An explicit call to commit() will initiate a commit without waiting for request results to be handled by script.

When committing, the transaction state is set to committing. The implementation must atomically write any changes to the database made by requests placed against the transaction. That is, either all of the changes must be written, or if an error occurs, such as a disk write error, the implementation must not write any of the changes to the database, and the steps to abort a transaction will be followed. 220. When a transaction is committed or aborted, its state is set to finished. The implementation must allow requests to be placed against the transaction whenever it is active. This is the case even if the transaction has not yet been started. Until the transaction is started the implementation must not execute these requests; however, the implementation must keep track of the requests and their order.

A transaction is said to be live from when it is created until its state is set to finished.

To cleanup Indexed Database transactions, run the following steps. They will return true if any transactions were cleaned up, or false otherwise.

  1. If there are no transactions with cleanup event loop matching the current event loop, return false.
  2. For each transactiontransaction with cleanup event loop matching the current event loop:
  3. Set transaction’s state to inactive.
  4. Clear transaction’s cleanup event loop.
  5. Return true. NOTE: These steps are invoked by HTML. They ensure that transactions created by a script call to transaction() are deactivated once the task that invoked the script has completed. The steps are run at most once for each transaction.

An event with type complete is fired at a transaction that has successfully committed.

An event with type abort is fired at a transaction that has aborted.

2.7.2. Transaction scheduling

The following constraints define when a transaction can be started:

  • A read-only transactionstx can start when there are no read/write transactions which:

  • Were created before tx; and

  • have overlapping scopes with tx; and

  • are not finished.

  • A read/write transactiontx can start when there are no transactions which:

  • Were created before tx; and

  • have overlapping scopes with tx; and

  • are not finished.

Implementations may impose additional constraints. For example, implementations are not required to start non-overlappingread/write transactions in parallel, or may impose limits on the number of started transactions.

NOTE: These constraints imply the following: - Any number of read-only transactions are allowed to be started concurrently, even if they have overlapping scopes.

  • As long as a read-only transaction is live, the data that the implementation returns through requests created with that transaction remains constant. That is, two requests to read the same piece of data yield the same result both for the case when data is found and the result is that data, and for the case when data is not found and a lack of data is indicated.
  • A read/write transaction is only affected by changes to object stores that are made using the transaction itself. The implementation ensures that another transaction does not modify the contents of object stores in the read/write transaction’s scope. The implementation also ensures that if the read/write transaction completes successfully, the changes written to object stores using the transaction can be committed to the database without merge conflicts.
  • If multiple read/write transactions are attempting to access the same object store (i.e. if they have overlapping scopes), the transaction that was created first is the transaction which gets access to the object store first, and it is the only transaction which has access to the object store until the transaction is finished.
  • Any transaction created after a read/write transaction sees the changes written by the read/write transaction. For example, if a read/write transaction A, is created, and later another transaction B, is created, and the two transactions have overlapping scopes, then transaction B sees any changes made to any object stores that are part of that overlapping scope. This also means that transaction B does not have access to any object stores in that overlapping scope until transaction A is finished.

2.7.3. Upgrade transactions

An upgrade transaction is a transaction with mode “versionchange”.

An upgrade transaction is automatically created when running the steps to upgrade a database after a connection is opened to a database, if a version greater than the current version is specified. This transaction will be active inside the upgradeneeded event handler.

NOTE: An upgrade transaction enables the creation, renaming, and deletion of object stores and indexes in a database. An upgrade transaction is exclusive. The steps to open a database connection ensure that only one connection to the database is open when an upgrade transaction is live. The upgradeneeded event isn’t fired, and thus the upgrade transaction isn’t started, until all other connections to the same database are closed. This ensures that all previous transactions are finished.

As long as an upgrade transaction is live, attempts to open more connections to the same database are delayed, and any attempts to use the same connection to start additional transactions by calling transaction() will throw an exception. This ensures that no other transactions are live concurrently, and also ensures that no new transactions are queued against the same database as long as the upgrade transaction is live.

This further ensures that once an upgrade transaction is complete, the set of object stores and indexes in a database remain constant for the lifetime of all subsequent connections and transactions.

2.8. Requests

Each asynchronous operation on a database is done using a request. Every request represents one operation.

A request has a processed flag which is initially false. This flag is set to true when the operation associated with the request has been executed.

A request is said to be processed when its processed flag is true.

A request has a done flag which is initially false. This flag is set to true when the result of the operation associated with the request is available.

A request has a source object.

A request has a result and an error, neither of which are accessible until its done flag is true.

A request has a transaction which is initially null. This will be set when a request is placed against a transaction using the steps to asynchronously execute a request.

When a request is made, a new request is returned with its done flag set to false. If a request completes successfully, its done flag is set to true, its result is set to the result of the request, and an event with type success is fired at the request.

If an error occurs while performing the operation, the request’s done flag is set to true, the request’s error is set to the error, and an event with type error is fired at the request.

A request’s get the parent algorithm returns the request’s transaction.

NOTE: Requests are not typically re-used, but there are exceptions. When a cursor is iterated, the success of the iteration is reported on the same request object used to open the cursor. And when an upgrade transaction is necessary, the same open request is used for both the upgradeneeded event and final result of the open operation itself. In some cases, the request’s done flag will be set to false, then set to true again, and the result can change or error could be set instead.

2.8.1. Open requests

An open request is a special type of request used when opening a connection or deleting a database. In addition to success and error events, blocked and upgradeneeded events may be fired at an open request to indicate progress.

The source of an open request is always null.

The transaction of an open request is null unless an upgradeneeded event has been fired.

An open request’s get the parent algorithm returns null.

2.8.2. Connection queues

Open requests are processed in a connection queue. The queue contains all open requests associated with an storage key and a name. Requests added to the connection queue processed in order and each request must run to completion before the next request is processed. An open request may be blocked on other connections, requiring those connections to close before the request can complete and allow further requests to be processed.

NOTE: A connection queue is not a task queue associated with an event loop, as the requests are processed outside any specific browsing context. The delivery of events to completed open request still goes through a task queue associated with the event loop of the context where the request was made.

2.9. Key range

Records can be retrieved from object stores and indexes using either keys or key ranges. A key range is a continuous interval over some data type used for keys.

A key range has an associated lower bound (null or a key).

A key range has an associated upper bound (null or a key).

A key range has an associated lower open flag. Unless otherwise stated it is false.

A key range has an associated upper open flag. Unless otherwise stated it is false.

A key range may have a lower boundequal to its upper bound. A key range must not have a lower boundgreater than its upper bound.

A key rangecontaining onlykey has both lower bound and upper bound equal to key.

A key is in a key rangerange if both of the following conditions are fulfilled:

  • The range’s lower bound is null, or it is less thankey, or it is both equal tokey and the range’s lower open flag is false.
  • The range’s upper bound is null, or it is greater thankey, or it is both equal tokey and the range’s upper open flag is false.

NOTE:- If a key range’s lower open flag is false, the lower boundkey of the key range is included in the range itself.

  • If a key range’s lower open flag is true, the lower boundkey of the key range is excluded from the range itself.
  • If a key range’s upper open flag is false, the upper boundkey of the key range is included in the range itself.
  • If a key range’s upper open flag is true, the upper boundkey of the key range is excluded from the range itself.

An unbounded key range is a key range that has both lower bound and upper bound equal to null. All keys are in an unbounded key range.

To convert a value to a key range with value and optional null disallowed flag, run these steps:

  1. If value is a key range, return value.
  2. If value is undefined or is null, then throw a “DataError” DOMException if null disallowed flag is true, or return an unbounded key range otherwise.
  3. Let key be the result of converting a value to a key with value. Rethrow any exceptions.
  4. If key is invalid, throw a “DataError” DOMException.
  5. Return a key rangecontaining onlykey.

2.10. Cursor

A cursor is used to iterate over a range of records in an index or an object store in a specific direction.

A cursor has a transaction, the transaction that was active when the cursor was created.

A cursor has a range of records in either an index or an object store.

A cursor has a source that indicates which index or an object store is associated with the records over which the cursor is iterating.

A cursor has a direction that determines whether it moves in monotonically increasing or decreasing order of the record keys when iterated, and if it skips duplicated values when iterating indexes. The direction of a cursor also determines if the cursor initial position is at the start of its source or at its end. A cursor’s direction is one of the following:

“next” This direction causes the cursor to be opened at the start of the source. When iterated, the cursor should yield all records, including duplicates, in monotonically increasing order of keys.

“nextunique” This direction causes the cursor to be opened at the start of the source. When iterated, the cursor should not yield records with the same key, but otherwise yield all records, in monotonically increasing order of keys. For every key with duplicate values, only the first record is yielded. When the source is an object store or an index with its unique flag set to true, this direction has exactly the same behavior as “next”.

“prev” This direction causes the cursor to be opened at the end of the source. When iterated, the cursor should yield all records, including duplicates, in monotonically decreasing order of keys.

“prevunique” This direction causes the cursor to be opened at the end of the source. When iterated, the cursor should not yield records with the same key, but otherwise yield all records, in monotonically decreasing order of keys. For every key with duplicate values, only the first record is yielded. When the source is an object store or an index with its unique flag set to true, this direction has exactly the same behavior as “prev”.

A cursor has a position within its range. It is possible for the list of records which the cursor is iterating over to change before the full range of the cursor has been iterated. In order to handle this, cursors maintain their position not as an index, but rather as a key of the previously returned record. For a forward iterating cursor, the next time the cursor is asked to iterate to the next record it returns the record with the lowest keygreater than the one previously returned. For a backwards iterating cursor, the situation is opposite and it returns the record with the highest keyless than the one previously returned.

For cursors iterating indexes the situation is a little bit more complicated since multiple records can have the same key and are therefore also sorted by value. When iterating indexes the cursor also has an object store position, which indicates the value of the previously found record in the index. Both position and the object store position are used when finding the next appropriate record.

A cursor has a key and a value which represent the key and the value of the last iterated record.

A cursor has a got value flag. When this flag is false, the cursor is either in the process of loading the next value or it has reached the end of its range. When it is true, it indicates that the cursor is currently holding a value and that it is ready to iterate to the next one.

If the source of a cursor is an object store, the effective object store of the cursor is that object store and the effective key of the cursor is the cursor’s position. If the source of a cursor is an index, the effective object store of the cursor is that index’s referenced object store and the effective key is the cursor’s object store position.

A cursor has a request, which is the request used to open the cursor.

A cursor also has a key only flag, that indicates whether the cursor’s value is exposed via the API.

2.11. Key generators

When a object store is created it can be specified to use a key generator. A key generator is used to generate keys for records inserted into an object store if not otherwise specified.

A key generator has a current number. The current number is always a positive integer less than or equal to 253 (9007199254740992) + 1. The initial value of a key generator’s current number is 1, set when the associated object store is created. The current number is incremented as keys are generated, and may be updated to a specific value by using explicit keys.

NOTE: Every object store that uses key generators uses a separate generator. That is, interacting with one object store never affects the key generator of any other object store.

Modifying a key generator’s current number is considered part of a database operation. This means that if the operation fails and the operation is reverted, the current number is reverted to the value it had before the operation started. This applies both to modifications that happen due to the current number getting increased by 1 when the key generator is used, and to modifications that happen due to a record being stored with a key value specified in the call to store the record.

Likewise, if a transaction is aborted, the current number of the key generator for each object store in the transaction’s scope is reverted to the value it had before the transaction was started.

The current number for a key generator never decreases, other than as a result of database operations being reverted. Deleting a record from an object store never affects the object store’s key generator. Even clearing all records from an object store, for example using the clear() method, does not affect the current number of the object store’s key generator.

When a record is stored and a key is not specified in the call to store the record, a key is generated.

To generate a key for an object storestore, run these steps:

  1. Let generator be store’s key generator.
  2. Let key be generator’s current number.
  3. If key is greater than 253 (9007199254740992), then return failure.
  4. Increase generator’s current number by 1.
  5. Return key. When a record is stored and a key is specified in the call to store the record, the associated key generator may be updated.

To possibly update the key generator for an object storestore with key, run these steps:

  1. If the type of key is not number, abort these steps.
  2. Let value be the value of key.
  3. Set value to the minimum of value and 253 (9007199254740992).
  4. Set value to the largest integer not greater than value.
  5. Let generator be store’s key generator.
  6. If value is greater than or equal to generator’s current number, then set generator’s current number to value + 1. NOTE: A key can be specified both for object stores which use in-line keys, by setting the property on the stored value which the object store’s key path points to, and for object stores which use out-of-line keys, by passing a key argument to the call to store the record. Only specified keys of typenumber can affect the current number of the key generator. Keys of typedate, array (regardless of the other keys they contain), binary, or string (regardless of whether they could be parsed as numbers) have no effect on the current number of the key generator. Keys of typenumber with value less than 1 do not affect the current number since they are always lower than the current number.

When the current number of a key generator reaches above the value 253 (9007199254740992) any subsequent attempts to use the key generator to generate a new key will result in a “ConstraintError” DOMException. It is still possible to insert records into the object store by specifying an explicit key, however the only way to use a key generator again for such records is to delete the object store and create a new one.

NOTE: This limit arises because integers greater than 9007199254740992 cannot be uniquely represented as ECMAScript Numbers. As an example, 9007199254740992 + 1 === 9007199254740992 in ECMAScript. As long as key generators are used in a normal fashion this limit will not be a problem. If you generate a new key 1000 times per second day and night, you won’t run into this limit for over 285000 years.

A practical result of this is that the first key generated for an object store is always 1 (unless a higher numeric key is inserted first) and the key generated for an object store is always a positive integer higher than the highest numeric key in the store. The same key is never generated twice for the same object store unless a transaction is rolled back.

Each object store gets its own key generator:

store1 = db.createObjectStore(“store1”,{ autoIncrement:true}); store1.put(“a”);// Will get key 1 store2 = db.createObjectStore(“store2”,{ autoIncrement:true}); store2.put(“a”);// Will get key 1 store1.put(“b”);// Will get key 2 store2.put(“b”);// Will get key 2If an insertion fails due to constraint violations or IO error, the key generator is not updated.

transaction.onerror =function(e){ e.preventDefault()}; store = db.createObjectStore(“store1”,{ autoIncrement:true}); index = store.createIndex(“index1”,“ix”,{ unique:true}); store.put({ ix:“a”});// Will get key 1 store.put({ ix:“a”});// Will fail store.put({ ix:“b”});// Will get key 2Removing items from an objectStore never affects the key generator. Including when clear() is called.

store = db.createObjectStore(“store1”,{ autoIncrement:true}); store.put(“a”);// Will get key 1 store.delete(1); store.put(“b”);// Will get key 2 store.clear(); store.put(“c”);// Will get key 3 store.delete(IDBKeyRange.lowerBound(0)); store.put(“d”);// Will get key 4Inserting an item with an explicit key affects the key generator if, and only if, the key is numeric and higher than the last generated key.

store = db.createObjectStore(“store1”,{ autoIncrement:true}); store.put(“a”);// Will get key 1 store.put(“b”,3);// Will use key 3 store.put(“c”);// Will get key 4 store.put(“d”,-10);// Will use key -10 store.put(“e”);// Will get key 5 store.put(“f”,6.00001);// Will use key 6.0001 store.put(“g”);// Will get key 7 store.put(“f”,8.9999);// Will use key 8.9999 store.put(“g”);// Will get key 9 store.put(“h”,“foo”);// Will use key “foo” store.put(“i”);// Will get key 10 store.put(“j”,1000);// Will use key 1000 store.put(“k”);// Will get key 11// All of these would behave the same if the objectStore used a// keyPath and the explicit key was passed inline in the objectAborting a transaction rolls back any increases to the key generator which happened during the transaction. This is to make all rollbacks consistent since rollbacks that happen due to crash never has a chance to commit the increased key generator value.

db.createObjectStore(“store”,{ autoIncrement:true}); trans1 = db.transaction(“store”,“readwrite”); store_t1 = trans1.objectStore(“store”); store_t1.put(“a”);// Will get key 1 store_t1.put(“b”);// Will get key 2 trans1.abort(); trans2 = db.transaction(“store”,“readwrite”); store_t2 = trans2.objectStore(“store”); store_t2.put(“c”);// Will get key 1 store_t2.put(“d”);// Will get key 2The following examples illustrate the different behaviors when trying to use in-line keys and key generators to save an object to an object store.

If the following conditions are true:

  • The object store has a key generator.
  • There is no in-line value for the key path property.

Then the value provided by the key generator is used to populate the key value. In the example below the key path for the object store is “foo.bar”. The actual object has no value for the bar property, { foo: {} }. When the object is saved in the object store the bar property is assigned a value of 1 because that is the next key generated by the key generator.

const store = db.createObjectStore(“store”,{ keyPath:“foo.bar”, autoIncrement:true}); store.put({ foo:{}}).onsuccess =function(e){const key = e.target.result; console.assert(key ===1);};If the following conditions are true:

  • The object store has a key generator.
  • There is a value for the key path property.

Then the value associated with the key path property is used. The auto-generated key is not used. In the example below the key path for the object store is “foo.bar”. The actual object has a value of 10 for the bar property, { foo: { bar: 10} }. When the object is saved in the object store the bar property keeps its value of 10, because that is the key value.

const store = db.createObjectStore(“store”,{ keyPath:“foo.bar”, autoIncrement:true}); store.put({ foo:{ bar:10}}).onsuccess =function(e){const key = e.target.result; console.assert(key ===10);};The following example illustrates the scenario when the specified in-line key is defined through a key path but there is no property matching it. The value provided by the key generator is then used to populate the key value and the system is responsible for creating as many properties as it requires to suffice the property dependencies on the hierarchy chain. In the example below the key path for the object store is “foo.bar.baz”. The actual object has no value for the foo property, { zip: {} }. When the object is saved in the object store the foo, bar, and baz properties are created each as a child of the other until a value for foo.bar.baz can be assigned. The value for foo.bar.baz is the next key generated by the object store.

const store = db.createObjectStore(“store”,{ keyPath:“foo.bar.baz”, autoIncrement:true}); store.put({ zip:{}}).onsuccess =function(e){const key = e.target.result; console.assert(key ===1); store.get(key).onsuccess =function(e){const value = e.target.result;// value will be: { zip: {}, foo: { bar: { baz: 1 } } } console.assert(value.foo.bar.baz ===1);};};Attempting to store a property on a primitive value will fail and throw an error. In the first example below the key path for the object store is “foo”. The actual object is a primitive with the value, 4. Trying to define a property on that primitive value fails. The same is true for arrays. Properties are not allowed on an array. In the second example below, the actual object is an array, 10. Trying to define a property on the array fails.

const store = db.createObjectStore(“store”,{ keyPath:“foo”, autoIncrement:true});// The key generation will attempt to create and store the key path// property on this primitive. store.put(4);// will throw DataError// The key generation will attempt to create and store the key path// property on this array. store.put(10);// will throw DataError

3. Exceptions

Each of the exceptions used in this document is a DOMException with a specific type. The exception types and properties such as legacy code value are defined in WEBIDL.

The table below lists the DOMExceptions used in this document along with a description of the exception type’s usage.

Type Description
AbortError A request was aborted.
ConstraintError A mutation operation in the transaction failed because a constraint was not satisfied.
DataCloneError The data being stored could not be cloned by the internal structured cloning algorithm.
DataError Data provided to an operation does not meet requirements.
InvalidAccessError An invalid operation was performed on an object.
InvalidStateError An operation was called on an object on which it is not allowed or at a time when it is not allowed, or if a request is made on a source object that has been deleted or removed.
NotFoundError The operation failed because the requested database object could not be found.
NotReadableError The operation failed because the underlying storage containing the requested data could not be read.
QuotaExceededError The operation failed because there was not enough remaining storage space, or the storage quota was reached and the user declined to give more space to the database.
SyntaxError The keyPath argument contains an invalid key path.
ReadOnlyError The mutating operation was attempted in a read-only transaction.
TransactionInactiveError A request was placed against a transaction which is currently not active, or which is finished.
UnknownError The operation failed for transient reasons unrelated to the database itself or not covered by any other error.
VersionError An attempt was made to open a database using a lower version than the existing version.

NOTE: Given that multiple Indexed DB operations can throw the same type of error, and that even a single operation can throw the same type of error for multiple reasons, implementations are encouraged to provide more specific messages to enable developers to identify the cause of errors.

4. API

The API methods return without blocking the calling thread. All asynchronous operations immediately return an IDBRequest instance. This object does not initially contain any information about the result of the operation. Once information becomes available, an event is fired on the request and the information becomes available through the properties of the IDBRequest instance.

The task source for these tasks is the database access task source.

4.1. The IDBRequest interface

The IDBRequest interface provides the means to access results of asynchronous requests to databases and database objects using event handler IDL attributesHTML.

Every method for making asynchronous requests returns an IDBRequest object that communicates back to the requesting application through events. This design means that any number of requests can be active on any database at a time.

In the following example, we open a database asynchronously. Various event handlers are registered for responding to various situations.

const request = indexedDB.open(‘AddressBook’,15); request.onsuccess =function(evt){…}; request.onerror =function(evt){…};Exposed=(Window,Worker) interfaceIDBRequest : EventTarget { readonlyattributeanyresult; readonlyattributeDOMException? error; readonlyattribute (IDBObjectStoreorIDBIndexorIDBCursor)? source; readonlyattributeIDBTransaction? transaction; readonlyattributeIDBRequestReadyStatereadyState; // Event handlers: attributeEventHandleronsuccess; attributeEventHandleronerror; }; enumIDBRequestReadyState { “pending”, “done” }; request . resultWhen a request is completed, returns the result, or undefined if the request failed. Throws a “InvalidStateError” DOMException if the request is still pending.

request . errorWhen a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws a “InvalidStateError” DOMException if the request is still pending.

request . sourceReturns the IDBObjectStore, IDBIndex, or IDBCursor the request was made against, or null if it was an open request.

request . transactionReturns the IDBTransaction the request was made within. If this as an open request, then it returns an upgrade transaction while it is live, or null otherwise.

request . readyStateReturns “pending” until a request is complete, then returns “done”.

The result getter steps are: 383. If this’s done flag is false, then throw an “InvalidStateError” DOMException. 384. Otherwise, return this’s result, or undefined if the request resulted in an error.

The error getter steps are: 386. If this’s done flag is false, then throw an “InvalidStateError” DOMException. 387. Otherwise, return this’s error, or null if no error occurred. The source getter steps are to return this’s source, or null if no source is set.

The transaction getter steps are to return this’s transaction.

NOTE: The transaction getter can return null for certain requests, such as for requests returned from open().

The readyState getter steps are to return “pending” if this’s done flag is false, and “done” otherwise.

The onsuccess attribute is an event handler IDL attribute whose event handler event type is success.

The onerror attribute is an event handler IDL attribute whose event handler event type is error event.

Methods on IDBDatabase that return a open request use an extended interface to allow listening to the blocked and upgradeneeded events.

Exposed=(Window,Worker) interfaceIDBOpenDBRequest : IDBRequest { // Event handlers: attributeEventHandleronblocked; attributeEventHandleronupgradeneeded; }; The onblocked attribute is an event handler IDL attribute whose event handler event type is blocked.

The onupgradeneeded attribute is an event handler IDL attribute whose event handler event type is upgradeneeded.

4.2. Event interfaces

This specification fires events with the following custom interfaces:

Exposed=(Window,Worker) interfaceIDBVersionChangeEvent : Event { constructor(DOMStringtype, optionalIDBVersionChangeEventIniteventInitDict = {}); readonlyattributeunsignedlonglongoldVersion; readonlyattributeunsignedlonglong? newVersion; }; dictionaryIDBVersionChangeEventInit : EventInit { unsignedlonglongoldVersion = 0; unsignedlonglong? newVersion = null; }; The oldVersion getter steps are to return the value it was initialized to. It represents the previous version of the database.

The newVersion getter steps are to return the value it was initialized to. It represents the new version of the database, or null if the database is being deleted. See the steps to upgrade a database.

Events are constructed as defined in DOM § 2.5 Constructing events.

To fire a version change event named e at target given oldVersion and newVersion, run these steps:

  1. Let event be the result of creating an event using IDBVersionChangeEvent.
  2. Set event’s type attribute to e.
  3. Set event’s bubbles and cancelable attributes to false.
  4. Set event’s oldVersion attribute to oldVersion.
  5. Set event’s newVersion attribute to newVersion.
  6. Let legacyOutputDidListenersThrowFlag be false.
  7. Dispatchevent at target with legacyOutputDidListenersThrowFlag.
  8. Return legacyOutputDidListenersThrowFlag.

NOTE: The return value of this algorithm is not always used.

4.3. The IDBFactory interface

Database objects are accessed through methods on the IDBFactory interface. A single object implementing this interface is present in the global scope of environments that support Indexed DB operations.

partialinterfacemixinWindowOrWorkerGlobalScope { SameObject readonlyattributeIDBFactoryindexedDB; }; The indexedDB attribute provides applications a mechanism for accessing capabilities of indexed databases.

Exposed=(Window,Worker) interfaceIDBFactory { NewObject IDBOpenDBRequestopen(DOMStringname, optional EnforceRange unsignedlonglongversion); NewObject IDBOpenDBRequestdeleteDatabase(DOMStringname); Promise<sequence<IDBDatabaseInfo>> databases(); shortcmp(anyfirst, anysecond); }; dictionaryIDBDatabaseInfo { DOMStringname; unsignedlonglongversion; }; request = indexedDB . open(name) Attempts to open a connection to the named database with the current version, or 1 if it does not already exist. If the request is successful request’s result will be the connection.

request = indexedDB . open(name, version) Attempts to open a connection to the named database with the specified version. If the database already exists with a lower version and there are open connections that don’t close in response to a versionchange event, the request will be blocked until they all close, then an upgrade will occur. If the database already exists with a higher version the request will fail. If the request is successful request’s result will be the connection.

request = indexedDB . deleteDatabase(name) Attempts to delete the named database. If the database already exists and there are open connections that don’t close in response to a versionchange event, the request will be blocked until they all close. If the request is successful request’s result will be null.

result = await indexedDB . databases() Returns a promise which resolves to a list of objects giving a snapshot of the names and versions of databases within the storage key.

This API is intended for web applications to introspect the use of databases, for example to clean up from earlier versions of a site’s code. Note that the result is a snapshot; there are no guarantees about the sequencing of the collection of the data or the delivery of the response with respect to requests to create, upgrade, or delete databases by this context or others.

The open(name, version) method steps are:

  1. If version is 0 (zero), throw a TypeError.
  2. Let environment be this’s relevant settings object.
  3. Let storageKey be the result of running obtain a storage key given environment. If failure is returned, then throw a “SecurityError” DOMException and abort these steps.
  4. Let request be a new open request.
  5. Run these steps in parallel:
  6. Let result be the result of opening a database connection, with storageKey, name, version if given and undefined otherwise, and request.

What happens if version is not given? If version is not given and a database with that name already exists, a connection will be opened without changing the version. If version is not given and no database with that name exists, a new database will be created with version equal to 1. 433. Queue a task to run these steps: 434. If result is an error, then: 435. Set request’s result to undefined. 436. Set request’s error to result. 437. Set request’s done flag to true. 438. Fire an event named error at request with its bubbles and cancelable attributes initialized to true. 439. Otherwise: 440. Set request’s result to result. 441. Set request’s done flag to true. 442. Fire an event named success at request. NOTE: If the steps above resulted in an upgrade transaction being run, these steps will run after that transaction finishes. This ensures that in the case where another version upgrade is about to happen, the success event is fired on the connection first so that the script gets a chance to register a listener for the versionchange event.

Why aren’t the steps to fire a success event or fire an error event used? There is no transaction associated with the request (at this point), so those steps — which activate an associated transaction before dispatch and deactivate the transaction after dispatch — do not apply. 446. Return a new IDBOpenDBRequest object for request. The deleteDatabase(name) method steps are:

  1. Let environment be this’s relevant settings object.
  2. Let storageKey be the result of running obtain a storage key given environment. If failure is returned, then throw a “SecurityError” DOMException and abort these steps.
  3. Let request be a new open request.
  4. Run these steps in parallel:
  5. Let result be the result of deleting a database, with storageKey, name, and request.
  6. Set request’s processed flag to true.
  7. Queue a task to run these steps:
  8. If result is an error, set request’s error to result, set request’s done flag to true, and fire an event named error at request with its bubbles and cancelable attributes initialized to true.
  9. Otherwise, set request’s result to undefined, set request’s done flag to true, and fire a version change event named success at request with result and null.

Why aren’t the steps to fire a success event or fire an error event used? There is no transaction associated with the request, so those steps — which activate an associated transaction before dispatch and deactivate the transaction after dispatch — do not apply. Also, the success event here is a IDBVersionChangeEvent which includes the oldVersion and newVersion details. 457. Return a new IDBOpenDBRequest object for request. The databases() method steps are:

  1. Let environment be this’s relevant settings object.
  2. Let storageKey be the result of running obtain a storage key given environment. If failure is returned, then return a promise rejected with a “SecurityError” DOMException
  3. Let p be a new promise.
  4. Run these steps in parallel:
  5. Let databases be the set of databases in storageKey. If this cannot be determined for any reason, then rejectp with an appropriate error (e.g. an “UnknownError” DOMException) and terminate these steps.
  6. Let result be a new list.
  7. For eachdb of databases:
  8. Let info be a new IDBDatabaseInfo dictionary.
  9. Set info’s name dictionary member to db’s name.
  10. Set info’s version dictionary member to db’s version.
  11. Appendinfo to result.
  12. Resolvep with result.
  13. Return p.

🚧 The databases() method is new in this edition. It is supported in Chrome 71, Edge 79, Firefox 126, and Safari 14. 🚧 result = indexedDB . cmp(key1, key2) Compares two values as keys. Returns -1 if key1 precedes key2, 1 if key2 precedes key1, and 0 if the keys are equal.

Throws a “DataError” DOMException if either input is not a valid key.

The cmp(first, second) method steps are:

  1. Let a be the result of converting a value to a key with first. Rethrow any exceptions.
  2. If a is invalid, throw a “DataError” DOMException.
  3. Let b be the result of converting a value to a key with second. Rethrow any exceptions.
  4. If b is invalid, throw a “DataError” DOMException.
  5. Return the results of comparing two keys with a and b.

4.4. The IDBDatabase interface

The IDBDatabase interface represents a connection to a database.

An IDBDatabase object must not be garbage collected if its associated connection’s close pending flag is false and it has one or more event listeners registers whose type is one of abort, error, or versionchange. If an IDBDatabase object is garbage collected, the associated connection must be closed.

Exposed=(Window,Worker) interfaceIDBDatabase : EventTarget { readonlyattributeDOMStringname; readonlyattributeunsignedlonglongversion; readonlyattributeDOMStringListobjectStoreNames; NewObject IDBTransactiontransaction((DOMStringorsequence<DOMString>) storeNames, optionalIDBTransactionModemode = “readonly”, optionalIDBTransactionOptionsoptions = {}); undefinedclose(); NewObject IDBObjectStorecreateObjectStore( DOMStringname, optionalIDBObjectStoreParametersoptions = {}); undefineddeleteObjectStore(DOMStringname); // Event handlers: attributeEventHandleronabort; attributeEventHandleronclose; attributeEventHandleronerror; attributeEventHandleronversionchange; }; enumIDBTransactionDurability { “default”, “strict”, “relaxed” }; dictionaryIDBTransactionOptions { IDBTransactionDurabilitydurability = “default”; }; dictionaryIDBObjectStoreParameters { (DOMStringorsequence<DOMString>)? keyPath = null; booleanautoIncrement = false; }; connection . nameReturns the name of the database.

connection . versionReturns the version of the database.

The name getter steps are to return this’s associated database’s name.

NOTE: The name attribute returns this name even if this’s close pending flag is true. In other words, the value of this attribute stays constant for the lifetime of the IDBDatabase instance.

The version getter steps are to return this’s version.

Is this the same as the database’s version? As long as the connection is open, this is the same as the connected database’s version. But once the connection has closed, this attribute will not reflect changes made with a later upgrade transaction. connection . objectStoreNamesReturns a list of the names of object stores in the database.

store = connection . createObjectStore(name , options) Creates a new object store with the given name and options and returns a new IDBObjectStore.

Throws a “InvalidStateError” DOMException if not called within an upgrade transaction.

connection . deleteObjectStore(name) Deletes the object store with the given name.

Throws a “InvalidStateError” DOMException if not called within an upgrade transaction.

The objectStoreNames getter steps are: 501. Let names be a list of the names of the object stores in this’s object store set. 502. Return the result (a DOMStringList) of creating a sorted name list with names.

Is this the same as the database’s object storenames? As long as the connection is open, this is the same as the connected database’s object storenames. But once the connection has closed, this attribute will not reflect changes made with a later upgrade transaction. The createObjectStore(name, options) method steps are:

  1. Let database be this’s associated database.
  2. Let transaction be database’s upgrade transaction if it is not null, or throw an “InvalidStateError” DOMException otherwise.
  3. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  4. Let keyPath be options’s keyPath member if it is not undefined or null, or null otherwise.
  5. If keyPath is not null and is not a valid key path, throw a “SyntaxError” DOMException.
  6. If an object storenamedname already exists in databasethrow a “ConstraintError” DOMException.
  7. Let autoIncrement be options’s autoIncrement member.
  8. If autoIncrement is true and keyPath is an empty string or any sequence (empty or otherwise), throw an “InvalidAccessError” DOMException.
  9. Let store be a new object store in database. Set the created object store’s name to name. If autoIncrement is true, then the created object store uses a key generator. If keyPath is not null, set the created object store’s key path to keyPath.
  10. Return a new object store handle associated with store and transaction. This method creates and returns a new object store with the given name in the connecteddatabase. Note that this method must only be called from within an upgrade transaction.

This method synchronously modifies the objectStoreNames property on the IDBDatabase instance on which it was called.

In some implementations it is possible for the implementation to run into problems after queuing a task to create the object store after the createObjectStore() method has returned. For example in implementations where metadata about the newly created object store is inserted into the database asynchronously, or where the implementation might need to ask the user for permission for quota reasons. Such implementations must still create and return an IDBObjectStore object, and once the implementation determines that creating the object store has failed, it must abort the transaction using the steps to abort a transaction using the appropriate error. For example if creating the object store failed due to quota reasons, a “QuotaExceededError” DOMException must be used as error.

The deleteObjectStore(name) method steps are:

  1. Let database be this’s associated database.
  2. Let transaction be database’s upgrade transaction if it is not null, or throw an “InvalidStateError” DOMException otherwise.
  3. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  4. Let store be the object storenamedname in database, or throw a “NotFoundError” DOMException if none.
  5. Remove store from this’s object store set.
  6. If there is an object store handle associated with store and transaction, remove all entries from its index set.
  7. Destroy store. This method destroys the object store with the given name in the connecteddatabase. Note that this method must only be called from within an upgrade transaction.

This method synchronously modifies the objectStoreNames property on the IDBDatabase instance on which it was called.

transaction = connection . transaction(scope , mode , options ) Returns a new transaction with the given scope (which can be a single object storename or an array of names), mode (“readonly” or “readwrite”), and additional options including durability (“default”, “strict” or “relaxed”).

The default mode is “readonly” and the default durability is “default”.

connection . close() Closes the connection once all running transactions have finished.

The transaction(storeNames, mode, options) method steps are:

  1. If a liveupgrade transaction is associated with the connection, throw an “InvalidStateError” DOMException.
  2. If this’s close pending flag is true, then throw an “InvalidStateError” DOMException.
  3. Let scope be the set of unique strings in storeNames if it is a sequence, or a set containing one string equal to storeNames otherwise.
  4. If any string in scope is not the name of an object store in the connecteddatabase, throw a “NotFoundError” DOMException.
  5. If scope is empty, throw an “InvalidAccessError” DOMException.
  6. If mode is not “readonly” or “readwrite”, throw a TypeError.
  7. Let transaction be a newly createdtransaction with this connection, mode, options’ durability member, and the set of object stores named in scope.
  8. Set transaction’s cleanup event loop to the current event loop.
  9. Return an IDBTransaction object representing transaction.

🚧 The durability option is new in this edition. It is supported in Chrome 82, Edge 82, Firefox 126, and Safari 15. 🚧 NOTE: The created transaction will follow the lifetime rules.

The close() method steps are:

  1. Run close a database connection with this connection. NOTE: The connection will not actually close until all outstanding transactions have completed. Subsequent calls to close() will have no effect.

The onabort attribute is an event handler IDL attribute whose event handler event type is abort.

The onclose attribute is an event handler IDL attribute whose event handler event type is close.

The onerror attribute is an event handler IDL attribute whose event handler event type is error.

The onversionchange attribute is an event handler IDL attribute whose event handler event type is versionchange.

4.5. The IDBObjectStore interface

The IDBObjectStore interface represents an object store handle.

Exposed=(Window,Worker) interfaceIDBObjectStore { attributeDOMStringname; readonlyattributeanykeyPath; readonlyattributeDOMStringListindexNames; SameObject readonlyattributeIDBTransactiontransaction; readonlyattributebooleanautoIncrement; NewObject IDBRequestput(anyvalue, optionalanykey); NewObject IDBRequestadd(anyvalue, optionalanykey); NewObject IDBRequestdelete(anyquery); NewObject IDBRequestclear(); NewObject IDBRequestget(anyquery); NewObject IDBRequestgetKey(anyquery); NewObject IDBRequestgetAll(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestgetAllKeys(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestcount(optionalanyquery); NewObject IDBRequestopenCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); NewObject IDBRequestopenKeyCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); IDBIndexindex(DOMStringname); NewObject IDBIndexcreateIndex(DOMStringname, (DOMStringorsequence<DOMString>) keyPath, optionalIDBIndexParametersoptions = {}); undefineddeleteIndex(DOMStringname); }; dictionaryIDBIndexParameters { booleanunique = false; booleanmultiEntry = false; }; store . nameReturns the name of the store.

store . name = newNameUpdates the name of the store to newName.

Throws “InvalidStateError” DOMException if not called within an upgrade transaction.

store . keyPathReturns the key path of the store, or null if none.

store . indexNamesReturns a list of the names of indexes in the store.

store . transactionReturns the associated transaction.

store . autoIncrementReturns true if the store has a key generator, and false otherwise.

The name getter steps are to return this’s name.

Is this the same as the object store’s name? As long as the transaction has not finished, this is the same as the associated object store’s name. But once the transaction has finished, this attribute will not reflect changes made with a later upgrade transaction. The name setter steps are:

  1. Let name be the given value.
  2. Let transaction be this’s transaction.
  3. Let store be this’s object store.
  4. If store has been deleted, throw an “InvalidStateError” DOMException.
  5. If transaction is not an upgrade transaction, throw an “InvalidStateError” DOMException.
  6. If transaction’s state is not active, throw a “TransactionInactiveError” DOMException.
  7. If store’s name is equal to name, terminate these steps.
  8. If an object storenamedname already exists in store’s database, throw a “ConstraintError” DOMException.
  9. Set store’s name to name.
  10. Set this’s name to name. The keyPath getter steps are to return this’s object store’s key path, or null if none. The key path is converted as a DOMString (if a string) or a sequence<DOMString> (if a list of strings), per WEBIDL.

NOTE: The returned value is not the same instance that was used when the object store was created. However, if this attribute returns an object (specifically an Array), it returns the same object instance every time it is inspected. Changing the properties of the object has no effect on the object store.

The indexNames getter steps are: 585. Let names be a list of the names of the indexes in this’s index set. 586. Return the result (a DOMStringList) of creating a sorted name list with names.

Is this the same as object store’s list of indexnames? As long as the transaction has not finished, this is the same as the associated object store’s list of indexnames. But once the transaction has finished, this attribute will not reflect changes made with a later upgrade transaction. The transaction getter steps are to return this’s transaction.

The autoIncrement getter steps are to return true if this’s object store has a key generator, and false otherwise.

The following methods throw a “ReadOnlyError” DOMException if called within a read-only transaction, and a “TransactionInactiveError” DOMException if called when the transaction is not active. request = store . put(value , key) request = store . add(value , key) Adds or updates a record in store with the given value and key.

If the store uses in-line keys and key is specified a “DataError” DOMException will be thrown.

If put() is used, any existing record with the key will be replaced. If add() is used, and if a record with the key already exists the request will fail, with request’s error set to a “ConstraintError” DOMException.

If successful, request’s result will be the record’s key.

request = store . delete(query) Deletes records in store with the given key or in the given key range in query.

If successful, request’s result will be undefined.

request = store . clear() Deletes all records in store.

If successful, request’s result will be undefined.

The put(value, key) method steps are to return the result of running add or put with this, value, key and the no-overwrite flag false.

The add(value, key) method steps are to return the result of running add or put with this, value, key and the no-overwrite flag true.

To add or put with handle, value, key, and no-overwrite flag, run these steps:

  1. Let transaction be handle’s transaction.
  2. Let store be handle’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  6. If store uses in-line keys and key was given, throw a “DataError” DOMException.
  7. If store uses out-of-line keys and has no key generator and key was not given, throw a “DataError” DOMException.
  8. If key was given, then:
  9. Let r be the result of converting a value to a key with key. Rethrow any exceptions.
  10. If r is invalid, throw a “DataError” DOMException.
  11. Let key be r.
  12. Let targetRealm be a user-agent defined Realm.
  13. Let clone be a clone of value in targetRealm during transaction. Rethrow any exceptions.

Why create a copy of the value? The value is serialized when stored. Treating it as a copy here allows other algorithms in this specification to treat it as an ECMAScript value, but implementations can optimize this if the difference in behavior is not observable. 618. If store uses in-line keys, then: 619. Let kpk be the result of extracting a key from a value using a key path with clone and store’s key path. Rethrow any exceptions. 620. If kpk is invalid, throw a “DataError” DOMException. 621. If kpk is not failure, let key be kpk. 622. Otherwise (kpk is failure): 623. If store does not have a key generator, throw a “DataError” DOMException. 624. Otherwise, if check that a key could be injected into a value with clone and store’s key path return false, throw a “DataError” DOMException. 625. Let operation be an algorithm to run store a record into an object store with store, clone, key, and no-overwrite flag. 626. Return the result (an IDBRequest) of running asynchronously execute a request with handle and operation. The delete(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  6. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  7. Let operation be an algorithm to run delete records from an object store with store and range.
  8. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the records to be deleted.

NOTE: Unlike other methods which take keys or key ranges, this method does not allow null to be given as key. This is to reduce the risk that a small bug would clear a whole object store.

The clear() method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  6. Let operation be an algorithm to run clear an object store with store.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation.

The following methods throw a “TransactionInactiveError” DOMException if called when the transaction is not active. request = store . get(query) Retrieves the value of the first record matching the given key or key range in query.

If successful, request’s result will be the value, or undefined if there was no matching record.

request = store . getKey(query) Retrieves the key of the first record matching the given key or key range in query.

If successful, request’s result will be the key, or undefined if there was no matching record.

request = store . getAll(query , count) Retrieves the values of the records matching the given key or key range in query (up to count if given).

If successful, request’s result will be an Array of the values.

request = store . getAllKeys(query , count) Retrieves the keys of records matching the given key or key range in query (up to count if given).

If successful, request’s result will be an Array of the keys.

request = store . count(query) Retrieves the number of records matching the given key or key range in query.

If successful, request’s result will be the count.

The get(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve a value from an object store with the current Realm record, store, and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record value to be retrieved. If a range is specified, the method retrieves the first existing value in that range.

NOTE: This method produces the same result if a record with the given key doesn’t exist as when a record exists, but has undefined as value. If you need to tell the two situations apart, you can use openCursor() with the same key. This will return a cursor with undefined as value if a record exists, or no cursor if no such record exists.

The getKey(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve a key from an object store with store and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record key to be retrieved. If a range is specified, the method retrieves the first existing key in that range.

The getAll(query, count) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve multiple values from an object store with the current Realm record, store, range, and count if given.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record values to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count records in range, only the first count will be retrieved.

The getAllKeys(query, count) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve multiple keys from an object store with store, range, and count if given.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record keys to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count keys in range, only the first count will be retrieved.

The count(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run count the records in a range with store and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the records to be counted. If null or not given, an unbounded key range is used.

The following methods throw a “TransactionInactiveError” DOMException if called when the transaction is not active. request = store . openCursor(query , direction = “next”) Opens a cursor over the records matching query, ordered by direction. If query is null, all records in store are matched.

If successful, request’s result will be an IDBCursorWithValue pointing at the first matching record, or null if there were no matching records.

request = store . openKeyCursor(query , direction = “next”) Opens a cursor with key only flag set to true over the records matching query, ordered by direction. If query is null, all records in store are matched.

If successful, request’s result will be an IDBCursor pointing at the first matching record, or null if there were no matching records.

The openCursor(query, direction) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let cursor be a new cursor with its transaction set to transaction, undefined position, direction set to direction, got value flag set to false, undefined key and value, source set to store, range set to range, and key only flag set to false.
  7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
  8. Let request be the result of running asynchronously execute a request with this and operation.
  9. Set cursor’s request to request.
  10. Return request. NOTE: The query parameter can be a key or key range (an IDBKeyRange) to use as the cursor’s range. If null or not given, an unbounded key range is used.

The openKeyCursor(query, direction) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let cursor be a new cursor with its transaction set to transaction, undefined position, direction set to direction, got value flag set to false, undefined key and value, source set to store, range set to range, and key only flag set to true.
  7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
  8. Let request be the result of running asynchronously execute a request with this and operation.
  9. Set cursor’s request to request.
  10. Return request. NOTE: The query parameter can be a key or key range (an IDBKeyRange) to use as the cursor’s range. If null or not given, an unbounded key range is used.

index = store . index(name) Returns an IDBIndex for the index named name in store.

index = store . createIndex(name, keyPath , options) Creates a new index in store with the given name, keyPath and options and returns a new IDBIndex. If the keyPath and options define constraints that cannot be satisfied with the data already in store the upgrade transaction will abort with a “ConstraintError” DOMException.

Throws an “InvalidStateError” DOMException if not called within an upgrade transaction.

store . deleteIndex(name) Deletes the index in store with the given name.

Throws an “InvalidStateError” DOMException if not called within an upgrade transaction.

The createIndex(name, keyPath, options) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If transaction is not an upgrade transaction, throw an “InvalidStateError” DOMException.
  4. If store has been deleted, throw an “InvalidStateError” DOMException.
  5. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  6. If an indexnamedname already exists in store, throw a “ConstraintError” DOMException.
  7. If keyPath is not a valid key path, throw a “SyntaxError” DOMException.
  8. Let unique be options’s unique member.
  9. Let multiEntry be options’s multiEntry member.
  10. If keyPath is a sequence and multiEntry is true, throw an “InvalidAccessError” DOMException.
  11. Let index be a new index in store. Set index’s name to name, key path to keyPath, unique flag to unique, and multiEntry flag to multiEntry.
  12. Add index to this’s index set.
  13. Return a new index handle associated with index and this. This method creates and returns a new index with the given name in the object store. Note that this method must only be called from within an upgrade transaction.

The index that is requested to be created can contain constraints on the data allowed in the index’s referenced object store, such as requiring uniqueness of the values referenced by the index’s key path. If the referenced object store already contains data which violates these constraints, this must not cause the implementation of createIndex() to throw an exception or affect what it returns. The implementation must still create and return an IDBIndex object, and the implementation must queue a task to abort the upgrade transaction which was used for the createIndex() call.

This method synchronously modifies the indexNames property on the IDBObjectStore instance on which it was called. Although this method does not return an IDBRequest object, the index creation itself is processed as an asynchronous request within the upgrade transaction.

In some implementations it is possible for the implementation to asynchronously run into problems creating the index after the createIndex method has returned. For example in implementations where metadata about the newly created index is queued up to be inserted into the database asynchronously, or where the implementation might need to ask the user for permission for quota reasons. Such implementations must still create and return an IDBIndex object, and once the implementation determines that creating the index has failed, it must run the steps to abort a transaction using an appropriate error. For example if creating the index failed due to quota reasons, a “QuotaExceededError” DOMException must be used as error and if the index can’t be created due to unique flag constraints, a “ConstraintError” DOMException must be used as error.

The asynchronous creation of indexes is observable in the following example:

const request1 = objectStore.put({name:“betty”},1);const request2 = objectStore.put({name:“betty”},2);const index = objectStore.createIndex(“by_name”,“name”,{unique:true});At the point where createIndex() called, neither of the requests have executed. When the second request executes, a duplicate name is created. Since the index creation is considered an asynchronous request, the index’s uniqueness constraint does not cause the second request to fail. Instead, the transaction will be aborted when the index is created and the constraint fails.

The index(name) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is finished, then throw an “InvalidStateError” DOMException.
  5. Let index be the indexnamedname in this’s index set if one exists, or throw a “NotFoundError” DOMException otherwise.
  6. Return an index handle associated with index and this. NOTE: Each call to this method on the same IDBObjectStore instance with the same name returns the same IDBIndex instance.

NOTE: The returned IDBIndex instance is specific to this IDBObjectStore instance. If this method is called on a different IDBObjectStore instance with the same name, a different IDBIndex instance is returned.

The deleteIndex(name) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If transaction is not an upgrade transaction, throw an “InvalidStateError” DOMException.
  4. If store has been deleted, throw an “InvalidStateError” DOMException.
  5. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  6. Let index be the indexnamedname in store if one exists, or throw a “NotFoundError” DOMException otherwise.
  7. Remove index from this’s index set.
  8. Destroy index. This method destroys the index with the given name in the object store. Note that this method must only be called from within an upgrade transaction.

This method synchronously modifies the indexNames property on the IDBObjectStore instance on which it was called. Although this method does not return an IDBRequest object, the index destruction itself is processed as an asynchronous request within the upgrade transaction.

4.6. The IDBIndex interface

The IDBIndex interface represents an index handle.

Exposed=(Window,Worker) interfaceIDBIndex { attributeDOMStringname; SameObject readonlyattributeIDBObjectStoreobjectStore; readonlyattributeanykeyPath; readonlyattributebooleanmultiEntry; readonlyattributebooleanunique; NewObject IDBRequestget(anyquery); NewObject IDBRequestgetKey(anyquery); NewObject IDBRequestgetAll(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestgetAllKeys(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestcount(optionalanyquery); NewObject IDBRequestopenCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); NewObject IDBRequestopenKeyCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); }; index . nameReturns the name of the index.

index . name = newNameUpdates the name of the store to newName.

Throws an “InvalidStateError” DOMException if not called within an upgrade transaction.

index . objectStoreReturns the IDBObjectStore the index belongs to.

index . keyPath Returns the key path of the index.

index . multiEntry Returns true if the index’s multiEntry flag is true.

index . unique Returns true if the index’s unique flag is true.

The name getter steps are to return this’s name.

Is this the same as the index’s name? As long as the transaction has not finished, this is the same as the associated index’s name. But once the transaction has finished, this attribute will not reflect changes made with a later upgrade transaction. The name setter steps are:

  1. Let name be the given value.
  2. Let transaction be this’s transaction.
  3. Let index be this’s index.
  4. If transaction is not an upgrade transaction, throw an “InvalidStateError” DOMException.
  5. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  6. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  7. If index’s name is equal to name, terminate these steps.
  8. If an indexnamedname already exists in index’s object store, throw a “ConstraintError” DOMException.
  9. Set index’s name to name.
  10. Set this’s name to name. The objectStore getter steps are to return this’s object store handle.

The keyPath getter steps are to return this’s index’s key path. The key path is converted as a DOMString (if a string) or a sequence<DOMString> (if a list of strings), per WEBIDL.

NOTE: The returned value is not the same instance that was used when the index was created. However, if this attribute returns an object (specifically an Array), it returns the same object instance every time it is inspected. Changing the properties of the object has no effect on the index.

The multiEntry getter steps are to return this’s index’s multiEntry flag.

The unique getter steps are to return this’s index’s unique flag.

The following methods throw an “TransactionInactiveError” DOMException if called when the transaction is not active. request = index . get(query) Retrieves the value of the first record matching the given key or key range in query.

If successful, request’s result will be the value, or undefined if there was no matching record.

request = index . getKey(query) Retrieves the key of the first record matching the given key or key range in query.

If successful, request’s result will be the key, or undefined if there was no matching record.

request = index . getAll(query , count) Retrieves the values of the records matching the given key or key range in query (up to count if given).

If successful, request’s result will be an Array of the values.

request = index . getAllKeys(query , count) Retrieves the keys of records matching the given key or key range in query (up to count if given).

If successful, request’s result will be an Array of the keys.

request = index . count(query) Retrieves the number of records matching the given key or key range in query.

If successful, request’s result will be the count.

The get(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve a referenced value from an index with the current Realm record, index, and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the referenced value to be retrieved. If a range is specified, the method retrieves the first existing record in that range.

NOTE: This method produces the same result if a record with the given key doesn’t exist as when a record exists, but has undefined as value. If you need to tell the two situations apart, you can use openCursor() with the same key. This will return a cursor with undefined as value if a record exists, or no cursor if no such record exists.

The getKey(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve a value from an index with index and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record key to be retrieved. If a range is specified, the method retrieves the first existing key in that range.

The getAll(query, count) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve multiple referenced values from an index with the current Realm record, index, range, and count if given.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the referenced values to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count records in range, only the first count will be retrieved.

The getAllKeys(query, count) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve multiple values from an index with index, range, and count if given.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record keys to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count keys in range, only the first count will be retrieved.

The count(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run count the records in a range with index and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the records to be counted. If null or not given, an unbounded key range is used.

The following methods throw an “TransactionInactiveError” DOMException if called when the transaction is not active. request = index . openCursor(query , direction = “next”) Opens a cursor over the records matching query, ordered by direction. If query is null, all records in index are matched.

If successful, request’s result will be an IDBCursorWithValue, or null if there were no matching records.

request = index . openKeyCursor(query , direction = “next”) Opens a cursor with key only flag set to true over the records matching query, ordered by direction. If query is null, all records in index are matched.

If successful, request’s result will be an IDBCursor, or null if there were no matching records.

The openCursor(query, direction) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let cursor be a new cursor with its transaction set to transaction, undefined position, direction set to direction, got value flag set to false, undefined key and value, source set to index, range set to range, and key only flag set to false.
  7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
  8. Let request be the result of running asynchronously execute a request with this and operation.
  9. Set cursor’s request to request.
  10. Return request. NOTE: The query parameter can be a key or key range (an IDBKeyRange) to use as the cursor’s range. If null or not given, an unbounded key range is used.

The openKeyCursor(query, direction) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let cursor be a new cursor with its transaction set to transaction, undefined position, direction set to direction, got value flag set to false, undefined key and value, source set to index, range set to range, and key only flag set to true.
  7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
  8. Let request be the result of running asynchronously execute a request with this and operation.
  9. Set cursor’s request to request.
  10. Return request. NOTE: The query parameter can be a key or key range (an IDBKeyRange) to use as the cursor’s range. If null or not given, an unbounded key range is used.

4.7. The IDBKeyRange interface

The IDBKeyRange interface represents a key range.

Exposed=(Window,Worker) interfaceIDBKeyRange { readonlyattributeanylower; readonlyattributeanyupper; readonlyattributebooleanlowerOpen; readonlyattributebooleanupperOpen; // Static construction methods: NewObject staticIDBKeyRangeonly(anyvalue); NewObject staticIDBKeyRangelowerBound(anylower, optionalbooleanopen = false); NewObject staticIDBKeyRangeupperBound(anyupper, optionalbooleanopen = false); NewObject staticIDBKeyRangebound(anylower, anyupper, optionalbooleanlowerOpen = false, optionalbooleanupperOpen = false); booleanincludes(anykey); }; range . lowerReturns the range’s lower bound, or undefined if none.

range . upperReturns the range’s upper bound, or undefined if none.

range . lowerOpenReturns the range’s lower open flag.

range . upperOpenReturns the range’s upper open flag.

The lower getter steps are to return the result of converting a key to a value with this’s lower bound if it is not null, or undefined otherwise.

The upper getter steps are to return the result of converting a key to a value with this’s upper bound if it is not null, or undefined otherwise.

The lowerOpen getter steps are to return this’s lower open flag.

The upperOpen getter steps are to return this’s upper open flag.

range = IDBKeyRange . only(key) Returns a new IDBKeyRange spanning only key.

range = IDBKeyRange . lowerBound(key , open = false) Returns a new IDBKeyRange starting at key with no upper bound. If open is true, key is not included in the range.

range = IDBKeyRange . upperBound(key , open = false) Returns a new IDBKeyRange with no lower bound and ending at key. If open is true, key is not included in the range.

range = IDBKeyRange . bound(lower, upper , lowerOpen = false , upperOpen = false) Returns a new IDBKeyRange spanning from lower to upper. If lowerOpen is true, lower is not included in the range. If upperOpen is true, upper is not included in the range.

The only(value) method steps are:

  1. Let key be the result of converting a value to a key with value. Rethrow any exceptions.

  2. If key is invalid, throw a “DataError” DOMException.

  3. Create and return a new key rangecontaining onlykey. The lowerBound(lower, open) method steps are:

  4. Let lowerKey be the result of converting a value to a key with lower. Rethrow any exceptions.

  5. If lowerKey is invalid, throw a “DataError” DOMException.

  6. Create and return a new key range with lower bound set to lowerKey, lower open flag set to open, upper bound set to null, and upper open flag set to true. The upperBound(upper, open) method steps are:

  7. Let upperKey be the result of converting a value to a key with upper. Rethrow any exceptions.

  8. If upperKey is invalid, throw a “DataError” DOMException.

  9. Create and return a new key range with lower bound set to null, lower open flag set to true, upper bound set to upperKey, and upper open flag set to open. The bound(lower, upper, lowerOpen, upperOpen) method steps are:

  10. Let lowerKey be the result of converting a value to a key with lower. Rethrow any exceptions.

  11. If lowerKey is invalid, throw a “DataError” DOMException.

  12. Let upperKey be the result of converting a value to a key with upper. Rethrow any exceptions.

  13. If upperKey is invalid, throw a “DataError” DOMException.

  14. If lowerKey is greater thanupperKey, throw a “DataError” DOMException.

  15. Create and return a new key range with lower bound set to lowerKey, lower open flag set to lowerOpen, upper bound set to upperKey and upper open flag set to upperOpen. range . includes(key) Returns true if key is included in the range, and false otherwise.

The includes(key) method steps are:

  1. Let k be the result of converting a value to a key with key. Rethrow any exceptions.
  2. If k is invalid, throw a “DataError” DOMException.
  3. Return true if k is in this range, and false otherwise.

4.8. The IDBCursor interface

Cursor objects implement the IDBCursor interface. There is only ever one IDBCursor instance representing a given cursor. There is no limit on how many cursors can be used at the same time.

Exposed=(Window,Worker) interfaceIDBCursor { readonlyattribute (IDBObjectStoreorIDBIndex) source; readonlyattributeIDBCursorDirectiondirection; readonlyattributeanykey; readonlyattributeanyprimaryKey; SameObject readonlyattributeIDBRequestrequest; undefinedadvance(EnforceRange unsignedlongcount); undefinedcontinue(optionalanykey); undefinedcontinuePrimaryKey(anykey, anyprimaryKey); NewObject IDBRequestupdate(anyvalue); NewObject IDBRequestdelete(); }; enumIDBCursorDirection { “next”, “nextunique”, “prev”, “prevunique” }; cursor . sourceReturns the IDBObjectStore or IDBIndex the cursor was opened from.

cursor . directionReturns the direction (“next”, “nextunique”, “prev” or “prevunique”) of the cursor.

cursor . keyReturns the key of the cursor. Throws a “InvalidStateError” DOMException if the cursor is advancing or is finished.

cursor . primaryKeyReturns the effective key of the cursor. Throws a “InvalidStateError” DOMException if the cursor is advancing or is finished.

cursor . requestReturns the request that was used to obtain this cursor.

The source getter steps are to return this’s source.

NOTE: The source attribute never returns null or throws an exception, even if the cursor is currently being iterated, has iterated past its end, or its transaction is not active.

The direction getter steps are to return this’s direction.

The key getter steps are to return the result of converting a key to a value with the cursor’s current key.

NOTE: If key returns an object (e.g. a Date or Array), it returns the same object instance every time it is inspected, until the cursor’s key is changed. This means that if the object is modified, those modifications will be seen by anyone inspecting the value of the cursor. However modifying such an object does not modify the contents of the database.

The primaryKey getter steps are to return the result of converting a key to a value with the cursor’s current effective key.

NOTE: If primaryKey returns an object (e.g. a Date or Array), it returns the same object instance every time it is inspected, until the cursor’s effective key is changed. This means that if the object is modified, those modifications will be seen by anyone inspecting the value of the cursor. However modifying such an object does not modify the contents of the database.

The request getter steps are to return this’s request.

🚧 The request attribute is new in this edition. It is supported in Chrome 76, Edge 79, Firefox 77, and Safari 15. 🚧 The following methods advance a cursor. Once the cursor has advanced, a success event will be fired at the same IDBRequest returned when the cursor was opened. The result will be the same cursor if a record was in range, or undefined otherwise. If called while the cursor is already advancing, an “InvalidStateError” DOMException will be thrown.

The following methods throw a “TransactionInactiveError” DOMException if called when the transaction is not active.

cursor . advance(count) Advances the cursor through the next countrecords in range.

cursor . continue() Advances the cursor to the next record in range.

cursor . continue(key) Advances the cursor to the next record in range matching or after key.

cursor . continuePrimaryKey(key, primaryKey) Advances the cursor to the next record in range matching or after key and primaryKey. Throws an “InvalidAccessError” DOMException if the source is not an index.

The advance(count) method steps are:

  1. If count is 0 (zero), throw a TypeError.
  2. Let transaction be this’s transaction.
  3. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  4. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  5. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  6. Set this’s got value flag to false.
  7. Let request be this’s request.
  8. Set request’s processed flag to false.
  9. Set request’s done flag to false.
  10. Let operation be an algorithm to run iterate a cursor with the current Realm record, this, and count.
  11. Run asynchronously execute a request with this’s source, operation, and request. NOTE: Calling this method more than once before new cursor data has been loaded - for example, calling advance() twice from the same onsuccess handler - results in an “InvalidStateError” DOMException being thrown on the second call because the cursor’s got value flag has been set to false.

The continue(key) method steps are:

  1. Let transaction be this’s transaction.
  2. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  3. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  5. If key is given, then:
  6. Let r be the result of converting a value to a key with key. Rethrow any exceptions.
  7. If r is invalid, throw a “DataError” DOMException.
  8. Let key be r.
  9. If key is less than or equal tothis’s position and this’s direction is “next” or “nextunique”, then throw a “DataError” DOMException.
  10. If key is greater than or equal tothis’s position and this’s direction is “prev” or “prevunique”, then throw a “DataError” DOMException.
  11. Set this’s got value flag to false.
  12. Let request be this’s request.
  13. Set request’s processed flag to false.
  14. Set request’s done flag to false.
  15. Let operation be an algorithm to run iterate a cursor with the current Realm record, this, and key (if given).
  16. Run asynchronously execute a request with this’s source, operation, and request. NOTE: Calling this method more than once before new cursor data has been loaded - for example, calling continue() twice from the same onsuccess handler - results in an “InvalidStateError” DOMException being thrown on the second call because the cursor’s got value flag has been set to false.

The continuePrimaryKey(key, primaryKey) method steps are:

  1. Let transaction be this’s transaction.
  2. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  3. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If this’s source is not an indexthrow an “InvalidAccessError” DOMException.
  5. If this’s direction is not “next” or “prev”, throw an “InvalidAccessError” DOMException.
  6. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  7. Let r be the result of converting a value to a key with key. Rethrow any exceptions.
  8. If r is invalid, throw a “DataError” DOMException.
  9. Let key be r.
  10. Let r be the result of converting a value to a key with primaryKey. Rethrow any exceptions.
  11. If r is invalid, throw a “DataError” DOMException.
  12. Let primaryKey be r.
  13. If key is less thanthis’s position and this’s direction is “next”, throw a “DataError” DOMException.
  14. If key is greater thanthis’s position and this’s direction is “prev”, throw a “DataError” DOMException.
  15. If key is equal tothis’s position and primaryKey is less than or equal tothis’s object store position and this’s direction is “next”, throw a “DataError” DOMException.
  16. If key is equal tothis’s position and primaryKey is greater than or equal tothis’s object store position and this’s direction is “prev”, throw a “DataError” DOMException.
  17. Set this’s got value flag to false.
  18. Let request be this’s request.
  19. Set request’s processed flag to false.
  20. Set request’s done flag to false.
  21. Let operation be an algorithm to run iterate a cursor with the current Realm record, this, key, and primaryKey.
  22. Run asynchronously execute a request with this’s source, operation, and request. NOTE: Calling this method more than once before new cursor data has been loaded - for example, calling continuePrimaryKey() twice from the same onsuccess handler - results in an “InvalidStateError” DOMException being thrown on the second call because the cursor’s got value flag has been set to false.

The following methods throw a “ReadOnlyError” DOMException if called within a read-only transaction, and a “TransactionInactiveError” DOMException if called when the transaction is not active. request = cursor . update(value) Updated the record pointed at by the cursor with a new value.

Throws a “DataError” DOMException if the effective object store uses in-line keys and the key would have changed.

If successful, request’s result will be the record’s key.

request = cursor . delete() Delete the record pointed at by the cursor with a new value.

If successful, request’s result will be undefined.

The update(value) method steps are:

  1. Let transaction be this’s transaction.
  2. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  3. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  4. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  5. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  6. If this’s key only flag is true, throw an “InvalidStateError” DOMException.
  7. Let targetRealm be a user-agent defined Realm.
  8. Let clone be a clone of value in targetRealm during transaction. Rethrow any exceptions.

Why create a copy of the value? The value is serialized when stored. Treating it as a copy here allows other algorithms in this specification to treat it as an ECMAScript value, but implementations can optimize this if the difference in behavior is not observable. 1060. If this’s effective object store uses in-line keys, then: 1061. Let kpk be the result of extracting a key from a value using a key path with clone and the key path of this’s effective object store. Rethrow any exceptions. 1062. If kpk is failure, invalid, or not equal tothis’s effective key, throw a “DataError” DOMException. 1063. Let operation be an algorithm to run store a record into an object store with this’s effective object store, clone, this’s effective key, and false. 1064. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: A result of storing a record into an object store is that if the record has been deleted since the cursor moved to it, a new record will be created.

The delete() method steps are:

  1. Let transaction be this’s transaction.
  2. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  3. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  4. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  5. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  6. If this’s key only flag is true, throw an “InvalidStateError” DOMException.
  7. Let operation be an algorithm to run delete records from an object store with this’s effective object store and this’s effective key.
  8. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. A cursor that has its key only flag set to false implements the IDBCursorWithValue interface as well.

Exposed=(Window,Worker) interfaceIDBCursorWithValue : IDBCursor { readonlyattributeanyvalue; }; cursor . valueReturns the cursor’s current value.

The value getter steps are to return this’s current value.

NOTE: If value returns an object, it returns the same object instance every time it is inspected, until the cursor’s value is changed. This means that if the object is modified, those modifications will be seen by anyone inspecting the value of the cursor. However modifying such an object does not modify the contents of the database.

4.9. The IDBTransaction interface

Transaction objects implement the following interface:

Exposed=(Window,Worker) interfaceIDBTransaction : EventTarget { readonlyattributeDOMStringListobjectStoreNames; readonlyattributeIDBTransactionModemode; readonlyattributeIDBTransactionDurabilitydurability; SameObject readonlyattributeIDBDatabasedb; readonlyattributeDOMException? error; IDBObjectStoreobjectStore(DOMStringname); undefinedcommit(); undefinedabort(); // Event handlers: attributeEventHandleronabort; attributeEventHandleroncomplete; attributeEventHandleronerror; }; enumIDBTransactionMode { “readonly”, “readwrite”, “versionchange” }; transaction . objectStoreNamesReturns a list of the names of object stores in the transaction’s scope. For an upgrade transaction this is all object stores in the database.

transaction . modeReturns the mode the transaction was created with (“readonly” or “readwrite”), or “versionchange” for an upgrade transaction.

transaction . durabilityReturns the durability hint the transaction was created with (“strict”, “relaxed”), or “default”).

transaction . dbReturns the transaction’s connection.

transaction . errorIf the transaction was aborted, returns the error (a DOMException) providing the reason.

The objectStoreNames getter steps are:

  1. Let names be a list of the names of the object stores in this’s scope.
  2. Return the result (a DOMStringList) of creating a sorted name list with names. NOTE: The contents of each list returned by this attribute does not change, but subsequent calls to this attribute during an upgrade transaction can return lists with different contents as object stores are created and deleted.

The mode getter steps are to return this’s mode.

The durability getter steps are to return this’s durability hint.

🚧 The durability attribute is new in this edition. It is supported in Chrome 82, Edge 82, Firefox 126, and Safari 15. 🚧 The db getter steps are to return this’s connection’s associated database.

The error getter steps are to return this’s error, or null if none.

NOTE: If this transaction was aborted due to a failed request, this will be the same as the request’s error. If this transaction was aborted due to an uncaught exception in an event handler, the error will be a “AbortError” DOMException. If the transaction was aborted due to an error while committing, it will reflect the reason for the failure (e.g. “QuotaExceededError”, “ConstraintError”, or “UnknownError” DOMException).

transaction . objectStore(name) Returns an IDBObjectStore in the transaction’s scope.

transaction . abort()Aborts the transaction. All pending requests will fail with a “AbortError” DOMException and all changes made to the database will be reverted.

transaction . commit()Attempts to commit the transaction. All pending requests will be allowed to complete, but no new requests will be accepted. This can be used to force a transaction to quickly finish, without waiting for pending requests to fire success events before attempting to commit normally.

The transaction will abort if a pending request fails, for example due to a constraint error. The success events for successful requests will still fire, but throwing an exception in an event handler will not abort the transaction. Similarly, error events for failed requests will still fire, but calling preventDefault() will not prevent the transaction from aborting.

The objectStore(name) method steps are:

  1. If this’s state is finished, then throw an “InvalidStateError” DOMException.
  2. Let store be the object storenamedname in this’s scope, or throw a “NotFoundError” DOMException if none.
  3. Return an object store handle associated with store and this. NOTE: Each call to this method on the same IDBTransaction instance with the same name returns the same IDBObjectStore instance.

NOTE: The returned IDBObjectStore instance is specific to this IDBTransaction. If this method is called on a different IDBTransaction, a different IDBObjectStore instance is returned.

The abort() method steps are:

  1. If this’s state is committing or finished, then throw an “InvalidStateError” DOMException.

  2. Set this’s state to inactive and run abort a transaction with this and null. The commit() method steps are:

  3. If this’s state is not active, then throw an “InvalidStateError” DOMException.

  4. Run commit a transaction with this.

🚧 The commit() method is new in this edition. It is supported in Chrome 76, Edge 79, Firefox 74, and Safari 15. 🚧 NOTE: It is not normally necessary to call commit() on a transaction. A transaction will automatically commit when all outstanding requests have been satisfied and no new requests have been made. This call can be used to start the commit process without waiting for events from outstanding requests to be dispatched.

The onabort attribute is an event handler IDL attribute whose event handler event type is abort.

The oncomplete attribute is an event handler IDL attribute whose event handler event type is complete.

The onerror attribute is an event handler IDL attribute whose event handler event type is error.

NOTE: To determine if a transaction has completed successfully, listen to the transaction’s complete event rather than the success event of a particular request, because the transaction can still fail after the success event fires.

5. Algorithms

5.1. Opening a database connection

To open a database connection with storageKey which requested the database to be opened, a database name, a database version, and a request, run these steps:

  1. Let queue be the connection queue for storageKey and name.
  2. Add request to queue.
  3. Wait until all previous requests in queue have been processed.
  4. Let db be the databasenamedname in storageKey, or null otherwise.
  5. If version is undefined, let version be 1 if db is null, or db’s version otherwise.
  6. If db is null, let db be a new database with namename, version 0 (zero), and with no object stores. If this fails for any reason, return an appropriate error (e.g. a “QuotaExceededError” or “UnknownError” DOMException).
  7. If db’s version is greater than version, return a newly created “VersionError” DOMException and abort these steps.
  8. Let connection be a new connection to db.
  9. Set connection’s version to version.
  10. If db’s version is less than version, then:
  11. Let openConnections be the set of all connections, except connection, associated with db.
  12. For eachentry of openConnections that does not have its close pending flag set to true, queue a task to fire a version change event named versionchange at entry with db’s version and version.

NOTE: Firing this event might cause one or more of the other objects in openConnections to be closed, in which case the versionchange event is not fired at those objects, even if that hasn’t yet been done. 1142. Wait for all of the events to be fired. 1143. If any of the connections in openConnections are still not closed, queue a task to fire a version change event named blocked at request with db’s version and version. 1144. Wait until all connections in openConnections are closed. 1145. Run upgrade a database using connection, version and request. 1146. If connection was closed, return a newly created “AbortError” DOMException and abort these steps. 1147. If the upgrade transaction was aborted, run the steps to close a database connection with connection, return a newly created “AbortError” DOMException and abort these steps. 1148. Return connection.

5.2. Closing a database connection

To close a database connection with a connection object, and an optional forced flag, run these steps:

  1. Set connection’s close pending flag to true.
  2. If the forced flag is true, then for each transactioncreated using connection run abort a transaction with transaction and newly created “AbortError” DOMException.
  3. Wait for all transactions created using connection to complete. Once they are complete, connection is closed.
  4. If the forced flag is true, then fire an event named close at connection.

NOTE: The close event only fires if the connection closes abnormally, e.g. if the storage key’s storage is cleared, or there is corruption or an I/O error. If close() is called explicitly the event does not fire. NOTE: Once a connection’s close pending flag has been set to true, no new transactions can be created using the connection. All methods that create transactions first check the connection’s close pending flag first and throw an exception if it is true.

NOTE: Once the connection is closed, this can unblock the steps to upgrade a database, and the steps to delete a database, which bothwait for connections to a given database to be closed before continuing.

5.3. Deleting a database

To delete a database with the storageKey that requested the database to be deleted, a database name, and a request, run these steps:

  1. Let queue be the connection queue for storageKey and name.
  2. Add request to queue.
  3. Wait until all previous requests in queue have been processed.
  4. Let db be the databasenamedname in storageKey, if one exists. Otherwise, return 0 (zero).
  5. Let openConnections be the set of all connections associated with db.
  6. For eachentry of openConnections that does not have its close pending flag set to true, queue a task to fire a version change event named versionchange at entry with db’s version and null.

NOTE: Firing this event might cause one or more of the other objects in openConnections to be closed, in which case the versionchange event is not fired at those objects, even if that hasn’t yet been done. 1165. Wait for all of the events to be fired. 1166. If any of the connections in openConnections are still not closed, queue a task to fire a version change event named blocked at request with db’s version and null. 1167. Wait until all connections in openConnections are closed. 1168. Let version be db’s version. 1169. Delete db. If this fails for any reason, return an appropriate error (e.g. “QuotaExceededError” or “UnknownError” DOMException). 1170. Return version.

5.4. Committing a transaction

To commit a transaction with the transaction to commit, run these steps:

  1. Set transaction’s state to committing.
  2. Run the following steps in parallel:
  3. Wait until every item in transaction’s request list is processed.
  4. If transaction’s state is no longer committing, then terminate these steps.
  5. Attempt to write any outstanding changes made by transaction to the database, considering transaction’s durability hint.
  6. If an error occurs while writing the changes to the database, then run abort a transaction with transaction and an appropriate type for the error, for example “QuotaExceededError” or “UnknownError” DOMException, and terminate these steps.
  7. Queue a task to run these steps:
  8. If transaction is an upgrade transaction, then set transaction’s connection’s associated database’s upgrade transaction to null.
  9. Set transaction’s state to finished.
  10. Fire an event named complete at transaction.

NOTE: Even if an exception is thrown from one of the event handlers of this event, the transaction is still committed since writing the database changes happens before the event takes place. Only after the transaction has been successfully written is the complete event fired. 1183. If transaction is an upgrade transaction, then let request be the request associated with transaction and set request’s transaction to null.

5.5. Aborting a transaction

To abort a transaction with the transaction to abort, and error, run these steps:

  1. All the changes made to the database by the transaction are reverted. For upgrade transactions this includes changes to the set of object stores and indexes, as well as the change to the version. Any object stores and indexes which were created during the transaction are now considered deleted for the purposes of other algorithms.
  2. If transaction is an upgrade transaction, run the steps to abort an upgrade transaction with transaction.

NOTE: This reverts changes to all connection, object store handle, and index handle instances associated with transaction. 1188. Set transaction’s state to finished. 1189. If error is not null, set transaction’s error to error. 1190. For eachrequest of transaction’s request list, abort the steps to asynchronously execute a request for request, set request’s processed flag to true, and queue a task to run these steps: 1191. Set request’s done flag to true. 1192. Set request’s result to undefined. 1193. Set request’s error to a newly created “AbortError” DOMException. 1194. Fire an event named error at request with its bubbles and cancelable attributes initialized to true. NOTE: This does not always result in any error events being fired. For example if a transaction is aborted due to an error while committing the transaction, or if it was the last remaining request that failed.

  1. Queue a task to run these steps:
  2. If transaction is an upgrade transaction, then set transaction’s connection’s associated database’s upgrade transaction to null.
  3. Fire an event named abort at transaction with its bubbles attribute initialized to true.
  4. If transaction is an upgrade transaction, then:
  5. Let request be the open request associated with transaction.
  6. Set request’s transaction to null.
  7. Set request’s result to undefined.
  8. Set request’s processed flag to false.
  9. Set request’s done flag to false.

5.6. Asynchronously executing a request

To asynchronously execute a request with the source object and an operation to perform on a database, and an optional request, run these steps:

These steps can be aborted at any point if the transaction the created request belongs to is aborted using the steps to abort a transaction.

  1. Let transaction be the transaction associated with source.
  2. Assert: transaction’s state is active.
  3. If request was not given, let request be a new request with source as source.
  4. Add request to the end of transaction’s request list.
  5. Run these steps in parallel:
  6. Wait until request is the first item in transaction’s request list that is not processed.
  7. Let result be the result of performing operation.
  8. If result is an error and transaction’s state is committing, then run abort a transaction with transaction and result, and terminate these steps.
  9. If result is an error, then revert all changes made by operation.

NOTE: This only reverts the changes done by this request, not any other changes made by the transaction. 1217. Set request’s processed flag to true. 1218. Queue a task to run these steps: 1219. Remove request from transaction’s request list. 1220. Set request’s done flag to true. 1221. If result is an error, then: 1222. Set request’s result to undefined. 1223. Set request’s error to result. 1224. Fire an error event at request. 1225. Otherwise: 1226. Set request’s result to result. 1227. Set request’s error to undefined. 1228. Fire a success event at request. 1229. Return request.

5.7. Upgrading a database

To upgrade a database with connection (a connection), a new version, and a request, run these steps:

  1. Let db be connection’s database.
  2. Let transaction be a new upgrade transaction with connection used as connection.
  3. Set transaction’s scope to connection’s object store set.
  4. Set db’s upgrade transaction to transaction.
  5. Set transaction’s state to inactive.
  6. Start transaction.

NOTE: Note that until this transaction is finished, no other connections can be opened to the same database. 1238. Let old version be db’s version. 1239. Set db’s version to version. This change is considered part of the transaction, and so if the transaction is aborted, this change is reverted. 1240. Set request’s processed flag to true. 1241. Queue a task to run these steps: 1242. Set request’s result to connection. 1243. Set request’s transaction to transaction. 1244. Set request’s done flag to true. 1245. Set transaction’s state to active. 1246. Let didThrow be the result of firing a version change event named upgradeneeded at request with old version and version. 1247. Set transaction’s state to inactive. 1248. If didThrow is true, run abort a transaction with transaction and a newly created “AbortError” DOMException. 1249. Wait for transaction to finish.

NOTE: Some of the algorithms invoked during the transaction’s lifetime, such as the steps to commit a transaction and the steps to abort a transaction, include steps specific to upgrade transactions.

5.8. Aborting an upgrade transaction

To abort an upgrade transaction with transaction, run these steps:

NOTE: These steps are run as needed by the steps to abort a transaction, which revert changes to the database including the set of associated object stores and indexes, as well as the change to the version.

  1. Let connection be transaction’s connection.
  2. Let database be connection’s database.
  3. Set connection’s version to database’s version if database previously existed, or 0 (zero) if database was newly created.

NOTE: This reverts the value of version returned by the IDBDatabase object. 1256. Set connection’s object store set to the set of object stores in database if database previously existed, or the empty set if database was newly created.

NOTE: This reverts the value of objectStoreNames returned by the IDBDatabase object. 1257. For each object store handlehandle associated with transaction, including those for object stores that were created or deleted during transaction: 1258. If handle’s object store was not newly created during transaction, set handle’s name to its object store’s name. 1259. Set handle’s index set to the set of indexes that reference its object store. NOTE: This reverts the values of name and indexNames returned by related IDBObjectStore objects.

How is this observable? Although script cannot access an object store by using the objectStore() method on an IDBTransaction instance after the transaction is aborted, it can still have references to IDBObjectStore instances where the name and indexNames properties can be queried. 1263. For each index handlehandle associated with transaction, including those for indexes that were created or deleted during transaction: 1264. If handle’s index was not newly created during transaction, set handle’s name to its index’s name. NOTE: This reverts the value of name returned by related IDBIndex objects.

How is this observable? Although script cannot access an index by using the index() method on an IDBObjectStore instance after the transaction is aborted, it can still have references to IDBIndex instances where the name property can be queried. NOTE: The name property of the IDBDatabase instance is not modified, even if the aborted upgrade transaction was creating a new database.

5.9. Firing a success event

To fire a success event at a request, run these steps:

  1. Let event be the result of creating an event using Event.
  2. Set event’s type attribute to “success”.
  3. Set event’s bubbles and cancelable attributes to false.
  4. Let transaction be request’s transaction.
  5. Let legacyOutputDidListenersThrowFlag be initially false.
  6. If transaction’s state is inactive, then set transaction’s state to active.
  7. Dispatchevent at request with legacyOutputDidListenersThrowFlag.
  8. If transaction’s state is active, then:
  9. Set transaction’s state to inactive.
  10. If legacyOutputDidListenersThrowFlag is true, then run abort a transaction with transaction and a newly created “AbortError” DOMException.
  11. If transaction’s request list is empty, then run commit a transaction with transaction.

5.10. Firing an error event

To fire an error event at a request, run these steps:

  1. Let event be the result of creating an event using Event.
  2. Set event’s type attribute to “error”.
  3. Set event’s bubbles and cancelable attributes to true.
  4. Let transaction be request’s transaction.
  5. Let legacyOutputDidListenersThrowFlag be initially false.
  6. If transaction’s state is inactive, then set transaction’s state to active.
  7. Dispatchevent at request with legacyOutputDidListenersThrowFlag.
  8. If transaction’s state is active, then:
  9. Set transaction’s state to inactive.
  10. If legacyOutputDidListenersThrowFlag is true, then run abort a transaction with transaction and a newly created “AbortError” DOMException and terminate these steps. This is done even if event’s canceled flag is false.

NOTE: This means that if an error event is fired and any of the event handlers throw an exception, transaction’s error property is set to an AbortError rather than request’s error, even if preventDefault() is never called. 1294. If event’s canceled flag is false, then run abort a transaction using transaction and request’s error, and terminate these steps. 1295. If transaction’s request list is empty, then run commit a transaction with transaction.

5.11. Clone a value

To make a clone of value in targetRealm during transaction, run these steps:

  1. Assert: transaction’s state is active.
  2. Set transaction’s state to inactive.

NOTE: The transaction is made inactive so that getters or other side effects triggered by the cloning operation are unable to make additional requests against the transaction. 1300. Let serialized be ?StructuredSerializeForStorage(value). 1301. Let clone be ?StructuredDeserialize(serialized, targetRealm). 1302. Set transaction’s state to active. 1303. Return clone.

6. Database operations

This section describes various operations done on the data in object stores and indexes in a database. These operations are run by the steps to asynchronously execute a request.

NOTE: Invocations of StructuredDeserialize() in the operation steps below can be asserted not to throw (as indicated by the ! prefix) because they operate only on previous output of StructuredSerializeForStorage().

6.1. Object store storage operation

To store a record into an object store with store, value, an optional key, and a no-overwrite flag, run these steps:

  1. If store uses a key generator, then:
  2. If key is undefined, then:
  3. Let key be the result of generating a key for store.
  4. If key is failure, then this operation failed with a “ConstraintError” DOMException. Abort this algorithm without taking any further steps.
  5. If store also uses in-line keys, then run inject a key into a value using a key path with value, key and store’s key path.
  6. Otherwise, run possibly update the key generator for store with key.
  7. If the no-overwrite flag was given to these steps and is true, and a record already exists in store with its key equal tokey, then this operation failed with a “ConstraintError” DOMException. Abort this algorithm without taking any further steps.
  8. If a record already exists in store with its key equal tokey, then remove the record from store using delete records from an object store.
  9. Store a record in store containing key as its key and !StructuredSerializeForStorage(value) as its value. The record is stored in the object store’s list of records such that the list is sorted according to the key of the records in ascending order.
  10. For each index which referencesstore:
  11. Let index key be the result of extracting a key from a value using a key path with value, index’s key path, and index’s multiEntry flag.
  12. If index key is an exception, or invalid, or failure, take no further actions for index, and continue these steps for the next index.

NOTE: An exception thrown in this step is not rethrown. 1321. If index’s multiEntry flag is false, or if index key is not an array key, and if index already contains a record with keyequal toindex key, and index’s unique flag is true, then this operation failed with a “ConstraintError” DOMException. Abort this algorithm without taking any further steps. 1322. If index’s multiEntry flag is true and index key is an array key, and if index already contains a record with keyequal to any of the subkeys of index key, and index’s unique flag is true, then this operation failed with a “ConstraintError” DOMException. Abort this algorithm without taking any further steps. 1323. If index’s multiEntry flag is false, or if index key is not an array key then store a record in index containing index key as its key and key as its value. The record is stored in index’s list of records such that the list is sorted primarily on the records keys, and secondarily on the records values, in ascending order. 1324. If index’s multiEntry flag is true and index key is an array key, then for each subkey of the subkeys of index key store a record in index containing subkey as its key and key as its value. The records are stored in index’s list of records such that the list is sorted primarily on the records keys, and secondarily on the records values, in ascending order.

NOTE: It is valid for there to be no subkeys. In this case no records are added to the index.

NOTE: Even if any member of subkeys is itself an array key, the member is used directly as the key for the index record. Nested array keys are not flattened or “unpacked” to produce multiple rows; only the outer-most array key is. 1325. Return key.

6.2. Object store retrieval operations

To retrieve a value from an object store with targetRealm, store and range, run these steps. They return undefined, an ECMAScript value, or an error (a DOMException):

  1. Let record be the first record in store’s list of records whose key is inrange, if any.

  2. If record was not found, return undefined.

  3. Let serialized be record’s value. If an error occurs while reading the value from the underlying storage, return a newly created “NotReadableError” DOMException.

  4. Return !StructuredDeserialize(serialized, targetRealm). To retrieve multiple values from an object store with targetRealm, store, range and optional count, run these steps. They return a sequence<any> or an error (a DOMException):

  5. If count is not given or is 0 (zero), let count be infinity.

  6. Let records be a list containing the first countrecords in store’s list of records whose key is inrange.

  7. Let list be an empty list.

  8. For eachrecord of records:

  9. Let serialized be record’s value. If an error occurs while reading the value from the underlying storage, return a newly created “NotReadableError” DOMException.

  10. Let entry be !StructuredDeserialize(serialized, targetRealm).

  11. Append entry to list.

  12. Return list converted to a sequence<any>. To retrieve a key from an object store with store and range, run these steps:

  13. Let record be the first record in store’s list of records whose key is inrange, if any.

  14. If record was not found, return undefined.

  15. Return the result of converting a key to a value with record’s key. To retrieve multiple keys from an object store with store, range and optional count, run these steps:

  16. If count is not given or is 0 (zero), let count be infinity.

  17. Let records be a list containing the first countrecords in store’s list of records whose key is inrange.

  18. Let list be an empty list.

  19. For eachrecord of records:

  20. Let entry be the result of converting a key to a value with record’s key.

  21. Append entry to list.

  22. Return list converted to a sequence<any>.

6.3. Index retrieval operations

To retrieve a referenced value from an index with targetRealm, index and range, run these steps:

  1. Let record be the first record in index’s list of records whose key is inrange, if any.

  2. If record was not found, return undefined.

  3. Let serialized be record’s referenced value.

  4. Return !StructuredDeserialize(serialized, targetRealm). To retrieve multiple referenced values from an index with targetRealm, index, range and optional count, run these steps:

  5. If count is not given or is 0 (zero), let count be infinity.

  6. Let records be a list containing the first countrecords in index’s list of records whose key is inrange.

  7. Let list be an empty list.

  8. For eachrecord of records:

  9. Let serialized be record’s referenced value.

  10. Let entry be !StructuredDeserialize(serialized, targetRealm).

  11. Append entry to list.

  12. Return list converted to a sequence<any>. NOTE: The values of an record in an index are the keys of records in the referenced object store.

To retrieve a value from an index with index and range, run these steps:

  1. Let record be the first record in index’s list of records whose key is inrange, if any.

  2. If record was not found, return undefined.

  3. Return the result of converting a key to a value with record’s value. To retrieve multiple values from an index with index, range and optional count, run these steps:

  4. If count is not given or is 0 (zero), let count be infinity.

  5. Let records be a list containing the first countrecords in index’s list of records whose key is inrange.

  6. Let list be an empty list.

  7. For eachrecord of records:

  8. Let entry be the result of converting a key to a value with record’s value.

  9. Append entry to list.

  10. Return list converted to a sequence<any>.

6.4. Object store deletion operation

To delete records from an object store with store and range, run these steps:

  1. Remove all records, if any, from store’s list of records with key inrange.
  2. For each index which referencesstore, remove every record from index’s list of records whose value is inrange, if any such records exist.
  3. Return undefined.

6.5. Record counting operation

To count the records in a range with source and range, run these steps:

  1. Let count be the number of records, if any, in source’s list of records with key inrange.
  2. Return count.

6.6. Object store clear operation

To clear an object store with store, run these steps:

  1. Remove all records from store.
  2. In all indexes which referencestore, remove all records.
  3. Return undefined.

6.7. Cursor iteration operation

To iterate a cursor with targetRealm, cursor, an optional key and primaryKey to iterate to, and an optional count, run these steps:

  1. Let source be cursor’s source.
  2. Let direction be cursor’s direction.
  3. Assert: if primaryKey is given, source is an index and direction is “next” or “prev”.
  4. Let records be the list of records in source.

NOTE:records is always sorted in ascendingkey order. In the case of source being an index, records is secondarily sorted in ascendingvalue order (where the value in an index is the key of the record in the referenced object store). 1401. Let range be cursor’s range. 1402. Let position be cursor’s position. 1403. Let object store position be cursor’s object store position. 1404. If count is not given, let count be 1. 1405. While count is greater than 0: 1406. Switch on direction:

“next” Let found record be the first record in records which satisfy all of the following requirements:

  • If key is defined, the record’s key is greater than or equal tokey.

  • If primaryKey is defined, the record’s key is equal tokey and the record’s value is greater than or equal toprimaryKey, or the record’s key is greater thankey.

  • If position is defined, and source is an object store, the record’s key is greater thanposition.

  • If position is defined, and source is an index, the record’s key is equal toposition and the record’s value is greater thanobject store position or the record’s key is greater thanposition.

  • The record’s key is inrange.

“nextunique” Let found record be the first record in records which satisfy all of the following requirements:

  • If key is defined, the record’s key is greater than or equal tokey.

  • If position is defined, the record’s key is greater thanposition.

  • The record’s key is inrange.

“prev” Let found record be the last record in records which satisfy all of the following requirements:

  • If key is defined, the record’s key is less than or equal tokey.

  • If primaryKey is defined, the record’s key is equal tokey and the record’s value is less than or equal toprimaryKey, or the record’s key is less thankey.

  • If position is defined, and source is an object store, the record’s key is less thanposition.

  • If position is defined, and source is an index, the record’s key is equal toposition and the record’s value is less thanobject store position or the record’s key is less thanposition.

  • The record’s key is inrange.

“prevunique” Let temp record be the last record in records which satisfy all of the following requirements:

  • If key is defined, the record’s key is less than or equal tokey.

  • If position is defined, the record’s key is less thanposition.

  • The record’s key is inrange.

If temp record is defined, let found record be the first record in records whose key is equal totemp record’s key.

NOTE: Iterating with “prevunique” visits the same records that “nextunique” visits, but in reverse order. 1407. If found record is not defined, then: 1408. Set cursor’s key to undefined. 1409. If source is an index, set cursor’s object store position to undefined. 1410. If cursor’s key only flag is false, set cursor’s value to undefined. 1411. Return null. 1412. Let position be found record’s key. 1413. If source is an index, let object store position be found record’s value. 1414. Decrease count by 1. 1415. Set cursor’s position to position. 1416. If source is an index, set cursor’s object store position to object store position. 1417. Set cursor’s key to found record’s key. 1418. If cursor’s key only flag is false, then: 1419. Let serialized be found record’s referenced value. 1420. Set cursor’s value to !StructuredDeserialize(serialized, targetRealm) 1421. Set cursor’s got value flag to true. 1422. Return cursor.

7. ECMAScript binding

This section defines how key values defined in this specification are converted to and from ECMAScript values, and how they may be extracted from and injected into ECMAScript values using key paths. This section references types and algorithms and uses some algorithm conventions from the ECMAScript Language Specification. ECMA-262 Conversions not detailed here are defined in WEBIDL.

7.1. Extract a key from a value

To extract a key from a value using a key path with value, keyPath and an optional multiEntry flag, run the following steps. The result of these steps is a key, invalid, or failure, or the steps may throw an exception.

  1. Let r be the result of evaluating a key path on a value with value and keyPath. Rethrow any exceptions.

  2. If r is failure, return failure.

  3. Let key be the result of converting a value to a key with r if the multiEntry flag is false, and the result of converting a value to a multiEntry key with r otherwise. Rethrow any exceptions.

  4. If key is invalid, return invalid.

  5. Return key. To evaluate a key path on a value with value and keyPath, run the following steps. The result of these steps is an ECMAScript value or failure, or the steps may throw an exception.

  6. If keyPath is a list of strings, then:

  7. Let result be a new Array object created as if by the expression .

  8. Let i be 0.

  9. For eachitem of keyPath:

  10. Let key be the result of recursively evaluating a key path on a value with item and value.

  11. Assert: key is not an abrupt completion.

  12. If key is failure, abort the overall algorithm and return failure.

  13. Let p be !ToString(i).

  14. Let status be CreateDataProperty(result, p, key).

  15. Assert: status is true.

  16. Increase i by 1.

  17. Return result.

NOTE: This will only ever “recurse” one level since key path sequences can’t ever be nested. 1445. If keyPath is the empty string, return value and skip the remaining steps. 1446. Let identifiers be the result of strictly splittingkeyPath on U+002E FULL STOP characters (.). 1447. For eachidentifier of identifiers, jump to the appropriate step below:

If Type(value) is String, and identifier is “length” Let value be a Number equal to the number of elements in value.

If value is an Array and identifier is “length” Let value be !ToLength(!Get(value, “length”)).

If value is a Blob and identifier is “size” Let value be a Number equal to value’s size.

If value is a Blob and identifier is “type” Let value be a String equal to value’s type.

If value is a File and identifier is “name” Let value be a String equal to value’s name.

If value is a File and identifier is “lastModified” Let value be a Number equal to value’s lastModified.

Otherwise 1448. If Type(value) is not Object, return failure. 1449. Let hop be !HasOwnProperty(value, identifier). 1450. If hop is false, return failure. 1451. Let value be !Get(value, identifier). 1452. If value is undefined, return failure. 1453. Assert: value is not an abrupt completion. 1454. Return value. NOTE: Assertions can be made in the above steps because this algorithm is only applied to values that are the output of StructuredDeserialize and only access “own” properties.

7.2. Inject a key into a value

NOTE: The key paths used in this section are always strings and never sequences, since it is not possible to create a object store which has a key generator and also has a key path that is a sequence.

To check that a key could be injected into a value with value and a keyPath, run the following steps. The result of these steps is either true or false.

  1. Let identifiers be the result of strictly splittingkeyPath on U+002E FULL STOP characters (.).
  2. Assert: identifiers is not empty.
  3. Remove the last item of identifiers.
  4. For each remaining identifier of identifiers, if any:
  5. If value is not an Object or an Array, return false.
  6. Let hop be !HasOwnProperty(value, identifier).
  7. If hop is false, return true.
  8. Let value be !Get(value, identifier).
  9. Return true if value is an Object or an Array, or false otherwise. NOTE: Assertions can be made in the above steps because this algorithm is only applied to values that are the output of StructuredDeserialize.

To inject a key into a value using a key path with value, a key and a keyPath, run these steps:

  1. Let identifiers be the result of strictly splittingkeyPath on U+002E FULL STOP characters (.).
  2. Assert: identifiers is not empty.
  3. Let last be the last item of identifiers and remove it from the list.
  4. For each remaining identifier of identifiers:
  5. Assert: value is an Object or an Array.
  6. Let hop be !HasOwnProperty(value, identifier).
  7. If hop is false, then:
  8. Let o be a new Object created as if by the expression ({}).
  9. Let status be CreateDataProperty(value, identifier, o).
  10. Assert: status is true.
  11. Let value be !Get(value, identifier).
  12. Assert: value is an Object or an Array.
  13. Let keyValue be the result of converting a key to a value with key.
  14. Let status be CreateDataProperty(value, last, keyValue).
  15. Assert: status is true. NOTE: Assertions can be made in the above steps because this algorithm is only applied to values that are the output of StructuredDeserialize, and the steps to check that a key could be injected into a value have been run.

7.3. Convert a key to a value

To convert a key to a value with key, run the following steps. The steps return an ECMAScript value.

  1. Let type be key’s type.
  2. Let value be key’s value.
  3. Switch on type:

numberReturn an ECMAScript Number value equal to value

stringReturn an ECMAScript String value equal to value

date 1491. Let date be the result of executing the ECMAScript Date constructor with the single argument value. 1492. Assert: date is not an abrupt completion. 1493. Return date. binary1495. Let len be value’s length. 1496. Let buffer be the result of executing the ECMAScript ArrayBuffer constructor with len. 1497. Assert: buffer is not an abrupt completion. 1498. Set the entries in buffer’s ArrayBufferData internal slot to the entries in value. 1499. Return buffer. array1501. Let array be the result of executing the ECMAScript Array constructor with no arguments. 1502. Assert: array is not an abrupt completion. 1503. Let len be value’s size. 1504. Let index be 0. 1505. While index is less than len: 1506. Let entry be the result of converting a key to a value with valueindex. 1507. Let status be CreateDataProperty(array, index, entry). 1508. Assert: status is true. 1509. Increase index by 1. 1510. Return array.

7.4. Convert a value to a key

To convert a value to a key with an ECMAScript value input, and an optional setseen, run the following steps. The result of these steps is a key or invalid, or the steps may throw an exception.

  1. If seen was not given, then let seen be a new empty set.
  2. If seencontainsinput, then return invalid.
  3. Jump to the appropriate step below:

If Type(input) is Number 1516. If input is NaN then return invalid. 1517. Otherwise, return a new key with typenumber and valueinput. If input is a Date (has a DateValue internal slot) 1519. Let ms be the value of input’s DateValue internal slot. 1520. If ms is NaN then return invalid. 1521. Otherwise, return a new key with typedate and valuems. If Type(input) is String 1523. Return a new key with typestring and valueinput. If input is a buffer source type1525. Let bytes be the result of getting a copy of the bytes held by the buffer sourceinput. Rethrow any exceptions. 1526. Return a new key with typebinary and valuebytes. If input is an Array exotic object1528. Let len be ?ToLength( ?Get(input, “length”)). 1529. Appendinput to seen. 1530. Let keys be a new empty list. 1531. Let index be 0. 1532. While index is less than len: 1533. Let hop be ?HasOwnProperty(input, index). 1534. If hop is false, return invalid. 1535. Let entry be ?Get(input, index). 1536. Let key be the result of converting a value to a key with arguments entry and seen. 1537. ReturnIfAbrupt(key). 1538. If key is invalid abort these steps and return invalid. 1539. Appendkey to keys. 1540. Increase index by 1. 1541. Return a new array key with valuekeys. Otherwise Return invalid.

To convert a value to a multiEntry key with an ECMAScript value input, run the following steps. The result of these steps is a key or invalid, or the steps may throw an exception.

  1. If input is an Array exotic object, then:
  2. Let len be ? ToLength( ?Get(input, “length”)).
  3. Let seen be a new set containing only input.
  4. Let keys be a new empty list.
  5. Let index be 0.
  6. While index is less than len:
  7. Let entry be Get(input, index).
  8. If entry is not an abrupt completion, then:
  9. Let key be the result of converting a value to a key with arguments entry and seen.
  10. If key is not invalid or an abrupt completion, and there is no item in keysequal tokey, then appendkey to keys.
  11. Increase index by 1.
  12. Return a new array key with value set to keys.
  13. Otherwise, return the result of converting a value to a key with argument input. Rethrow any exceptions. NOTE: These steps are similar to those to convert a value to a key but if the top-level value is an Array then members which can not be converted to keys are ignored, and duplicates are removed.

For example, the value 10, 20, null, 30, 20 is converted to an array key with subkeys 10, 20, 30.

8. Privacy considerations

This section is non-normative.

8.1. User tracking

A third-party host (or any object capable of getting content distributed to multiple sites) could use a unique identifier stored in its client-side database to track a user across multiple sessions, building a profile of the user’s activities. In conjunction with a site that is aware of the user’s real id object (for example an e-commerce site that requires authenticated credentials), this could allow oppressive groups to target individuals with greater accuracy than in a world with purely anonymous Web usage.

There are a number of techniques that can be used to mitigate the risk of user tracking:

Blocking third-party storage User agents may restrict access to the database objects to scripts originating at the domain of the top-level document of the browsing context, for instance denying access to the API for pages from other domains running in iframes.

Expiring stored data User agents may automatically delete stored data after a period of time.

This can restrict the ability of a site to track a user, as the site would then only be able to track the user across multiple sessions when she authenticates with the site itself (e.g. by making a purchase or logging in to a service).

However, this also puts the user’s data at risk.

Treating persistent storage as cookies User agents should present the database feature to the user in a way that associates them strongly with HTTP session cookies. COOKIES

This might encourage users to view such storage with healthy suspicion.

Site-specific safe-listing of access to databases User agents may require the user to authorize access to databases before a site can use the feature.

Attribution of third-party storage User agents may record the origins of sites that contained content from third-party origins that caused data to be stored.

If this information is then used to present the view of data currently in persistent storage, it would allow the user to make informed decisions about which parts of the persistent storage to prune. Combined with a blocklist (“delete this data and prevent this domain from ever storing data again”), the user can restrict the use of persistent storage to sites that she trusts.

Shared blocklists User agents may allow users to share their persistent storage domain blocklists.

This would allow communities to act together to protect their privacy.

While these suggestions prevent trivial use of this API for user tracking, they do not block it altogether. Within a single domain, a site can continue to track the user during a session, and can then pass all this information to the third party along with any identifying information (names, credit card numbers, addresses) obtained by the site. If a third party cooperates with multiple sites to obtain such information, a profile can still be created.

However, user tracking is to some extent possible even with no cooperation from the user agent whatsoever, for instance by using session identifiers in URLs, a technique already commonly used for innocuous purposes but easily repurposed for user tracking (even retroactively). This information can then be shared with other sites, using visitors’ IP addresses and other user-specific data (e.g. user-agent headers and configuration settings) to combine separate sessions into coherent user profiles.

If the user interface for persistent storage presents data in the persistent storage features described in this specification separately from data in HTTP session cookies, then users are likely to delete data in one and not the other. This would allow sites to use the two features as redundant backup for each other, defeating a user’s attempts to protect his privacy.

8.3. Sensitivity of data

User agents should treat persistently stored data as potentially sensitive; it is quite possible for e-mails, calendar appointments, health records, or other confidential documents to be stored in this mechanism.

To this end, user agents should ensure that when deleting data, it is promptly deleted from the underlying storage.

9. Security considerations

9.1. DNS spoofing attacks

Because of the potential for DNS spoofing attacks, one cannot guarantee that a host claiming to be in a certain domain really is from that domain. To mitigate this, pages can use TLS. Pages using TLS can be sure that only pages using TLS that have certificates identifying them as being from the same domain can access their databases.

9.2. Cross-directory attacks

Different authors sharing one host name, for example users hosting content on geocities.com, all share one set of databases.

There is no feature to restrict the access by pathname. Authors on shared hosts are therefore recommended to avoid using these features, as it would be trivial for other authors to read the data and overwrite it.

NOTE: Even if a path-restriction feature was made available, the usual DOM scripting security model would make it trivial to bypass this protection and access the data from any path.

9.3. Implementation risks

The two primary risks when implementing these persistent storage features are letting hostile sites read information from other domains, and letting hostile sites write information that is then read from other domains.

Letting third-party sites read data that is not supposed to be read from their domain causes information leakage, For example, a user’s shopping wish list on one domain could be used by another domain for targeted advertising; or a user’s work-in-progress confidential documents stored by a word-processing site could be examined by the site of a competing company.

Letting third-party sites write data to the persistent storage of other domains can result in information spoofing, which is equally dangerous. For example, a hostile site could add records to a user’s wish list; or a hostile site could set a user’s session identifier to a known ID that the hostile site can then use to track the user’s actions on the victim site.

Thus, strictly following the storage key partitioning model described in this specification is important for user security.

If host names or database names are used to construct paths for persistence to a file system they must be appropriately escaped to prevent an adversary from accessing information from other storage keys using relative paths such as “../”.

9.4. Persistence risks

Practical implementations will persist data to a non-volatile storage medium. Data will be serialized when stored and deserialized when retrieved, although the details of the serialization format will be user-agent specific. User agents are likely to change their serialization format over time. For example, the format may be updated to handle new data types, or to improve performance. To satisfy the operational requirements of this specification, implementations must therefore handle older serialization formats in some way. Improper handling of older data can result in security issues. In addition to basic serialization concerns, serialized data could encode assumptions which are not valid in newer versions of the user agent.

A practical example of this is the RegExp type. The StructuredSerializeForStorage operation allows serializing RegExp objects. A typical user agent will compile a regular expression into native machine instructions, with assumptions about how the input data is passed and results returned. If this internal state was serialized as part of the data stored to the database, various problems could arise when the internal representation was later deserialized. For example, the means by which data was passed into the code could have changed. Security bugs in the compiler output could have been identified and fixed in updates to the user agent, but remain in the serialized internal state.

User agents must identify and handle older data appropriately. One approach is to include version identifiers in the serialization format, and to reconstruct any internal state from script-visible state when older data is encountered.

10. Accessibility considerations

This section is non-normative.

The API described by this specification has limited accesibility considerations:

  • It does not provide for visual rendering of content, or control over color.
  • It does not provide features to accept user input.
  • It does not provide user interaction features.
  • It does not define document semantics.
  • It does not provide time-based visual media.
  • It does not allow time limits.
  • It does not directly provide content for end-users, either in textual, graphical or other or non-textual form.
  • It does not define a transmission protocol.

The API does allow storage of structured content. Textual content can be stored as strings. Support exists in the API for developers to store alternative non-textual content such as images or audio as Blob, File, or ImageData objects. Developers producing dynamic content applications using the API should ensure that the content is accessible to users with a variety of technologies and needs.

While the API itself does not define a specific mechanism for it, storage of structured content also allows developers to store internationalized content, using different records or structure within records to hold language alternatives.

The API does not define or require any a user agent to generate a user interface to enable interaction with the API. User agents may optionally provide user interface elements to support the API. Examples include prompts to users when additional storage quota is required, functionality to observe storage used by particular web sites, or tools specific to the API’s storage such as inspecting, modifying, or deleting records. Any such user interface elements must be designed with accessibility tools in mind. For example, a user interface presenting the fraction of storage quota used in graphical form must also provide the same data to tools such as screen readers.

11. Revision history

This section is non-normative.

The following is an informative summary of the changes since the last publication of this specification. A complete revision history can be found here. For the revision history of the first edition, see that document’s Revision History. For the revision history of the second edition, see that document’s Revision History.

  • The cleanup Indexed Database transactions algorithm now returns a value for integration with other specs. (PR #232)
  • Updated partial interface definition since WindowOrWorkerGlobalScope is now a mixin (PR #238).
  • Added databases() method. (Issue #31)
  • Added commit() method. (Issue #234)
  • Added request attribute. (Issue #255)
  • Removed handling for nonstandard lastModifiedDate property of File objects. (Issue #215)
  • Remove escaping includes() method. (Issue #294)
  • Restrict array keys to Array exotic objects (i.e. disallow proxies). (Issue #309)
  • Transactions are now temporarily made inactive during clone operations.
  • Added durability option and durability attribute. (Issue #50)
  • Specified § 2.7.2 Transaction scheduling more precisely and disallow starting read/write transactions while read-only transactions with overlapping scope are running. (Issue #253)
  • Added Accessibility considerations section. (Issue #327)
  • Used infra’s list sorting definition. (Issue #346)
  • Added a definition for live transactions, and renamed “run an upgrade transaction” to upgrade a database, to disambiguate “running”. (Issue #408)
  • Specified the DOMException type for failures when reading a value from the underlying storage in § 6.2 Object store retrieval operations. (Issue #423)

12. Acknowledgements

This section is non-normative.

Special thanks to Nikunj Mehta, the original author of the first edition, and Jonas Sicking, Eliot Graff, Andrei Popescu, and Jeremy Orlow, additional editors of the first edition.

Garret Swart was extremely influential in the design of this specification.

Thanks to Tab Atkins, Jr. for creating and maintaining Bikeshed, the specification authoring tool used to create this document, and for his general authoring advice.

Special thanks to Abhishek Shanthkumar, Adam Klein, Addison Phillips, Adrienne Walker, Alec Flett, Andrea Marchesini, Andreas Butler, Andrew Sutherland, Anne van Kesteren, Anthony Ramine, Ari Chivukula, Arun Ranganathan, Ben Dilts, Ben Turner, Bevis Tseng, Boris Zbarsky, Brett Zamir, Chris Anderson, Dana Florescu, Danillo Paiva, David Grogan, Domenic Denicola, Dominique Hazael-Massieux, Evan Stade, Glenn Maynard, Hans Wennborg, Isiah Meadows, Israel Hilerio, Jake Archibald, Jake Drew, Jerome Hode, Josh Matthews, João Eiras, Kagami Sascha Rosylight, Kang-Hao Lu, Kris Zyp, Kristof Degrave, Kyaw Tun, Kyle Huey, Laxminarayan G Kamath A, Maciej Stachowiak, Marcos Cáceres, Margo Seltzer, Marijn Kruisselbrink, Ms2ger, Odin Omdal, Olli Pettay, Pablo Castro, Philip Jägenstedt, Shawn Wilsher, Simon Pieters, Tobie Langel, Victor Costan, Xiaoqian Wu, Yannic Bonenberger, Yaron Tausky, Yonathan Randolph, and Zhiqiang Zhang, all of whose feedback and suggestions have led to improvements to this specification.

User agents need to store large numbers of objects locally in order to satisfy off-line data requirements of Web applications. WEBSTORAGE is useful for storing pairs of keys and their corresponding values. However, it does not provide in-order retrieval of keys, efficient searching over values, or storage of duplicate values for a key.

This specification provides a concrete API to perform advanced key-value data management that is at the heart of most sophisticated query processors. It does so by using transactional databases to store keys and their corresponding values (one or more per key), and providing a means of traversing keys in a deterministic order. This is often implemented through the use of persistent B-tree data structures that are considered efficient for insertion and deletion as well as in-order traversal of very large numbers of data records.

The following example uses the API to access a “library” database. It has a “books” object store that holds books records stored by their “isbn” property as the primary key. Book records have a “title” property. This example artificially requires that book titles are unique. The code enforces this by creating an index named “by_title” with the unique option set. This index is used to look up books by title, and will prevent adding books with non-unique titles.

Book records also have an “author” property, which is not required to be unique. The code creates another index named “by_author” to allow look-ups by this property.

The code first opens a connection to the database. The upgradeneeded event handler code creates the object store and indexes, if needed. The success event handler code saves the opened connection for use in later examples.

const request = indexedDB.open(“library”);let db; request.onupgradeneeded =function(){// The database did not previously exist, so create object stores and indexes.const db = request.result;const store = db.createObjectStore(“books”,{keyPath:“isbn”});const titleIndex = store.createIndex(“by_title”,“title”,{unique:true});const authorIndex = store.createIndex(“by_author”,“author”);// Populate with initial data. store.put({title:“Quarry Memories”, author:“Fred”, isbn:123456}); store.put({title:“Water Buffaloes”, author:“Fred”, isbn:234567}); store.put({title:“Bedrock Nights”, author:“Barney”, isbn:345678});}; request.onsuccess =function(){ db = request.result;};The following example populates the database using a transaction.

const tx = db.transaction(“books”,“readwrite”);const store = tx.objectStore(“books”); store.put({title:“Quarry Memories”, author:“Fred”, isbn:123456}); store.put({title:“Water Buffaloes”, author:“Fred”, isbn:234567}); store.put({title:“Bedrock Nights”, author:“Barney”, isbn:345678}); tx.oncomplete =function(){// All requests have succeeded and the transaction has committed.};The following example looks up a single book in the database by title using an index.

const tx = db.transaction(“books”,“readonly”);const store = tx.objectStore(“books”);const index = store.index(“by_title”);const request = index.get(“Bedrock Nights”); request.onsuccess =function(){const matching = request.result;if(matching !==undefined){// A match was found. report(matching.isbn, matching.title, matching.author);}else{// No match was found. report(null);}};The following example looks up all books in the database by author using an index and a cursor.

const tx = db.transaction(“books”,“readonly”);const store = tx.objectStore(“books”);const index = store.index(“by_author”);const request = index.openCursor(IDBKeyRange.only(“Fred”)); request.onsuccess =function(){const cursor = request.result;if(cursor){// Called for each matching record. report(cursor.value.isbn, cursor.value.title, cursor.value.author); cursor.continue();}else{// No more matching records. report(null);}};The following example shows one way to handle errors when a request fails.

const tx = db.transaction(“books”,“readwrite”);const store = tx.objectStore(“books”);const request = store.put({title:“Water Buffaloes”, author:“Slate”, isbn:987654}); request.onerror =function(event){// The uniqueness constraint of the “by_title” index failed. report(request.error);// Could call event.preventDefault() to prevent the transaction from aborting.}; tx.onabort =function(){// Otherwise the transaction will automatically abort due the failed request. report(tx.error);};The database connection can be closed when it is no longer needed.

db.close();In the future, the database might have grown to contain other object stores and indexes. The following example shows one way to handle migrating from an older version.

const request = indexedDB.open(“library”,3);// Request version 3.let db; request.onupgradeneeded =function(event){const db = request.result;if(event.oldVersion <1){// Version 1 is the first version of the database.const store = db.createObjectStore(“books”,{keyPath:“isbn”});const titleIndex = store.createIndex(“by_title”,“title”,{unique:true});const authorIndex = store.createIndex(“by_author”,“author”);}if(event.oldVersion <2){// Version 2 introduces a new index of books by year.const bookStore = request.transaction.objectStore(“books”);const yearIndex = bookStore.createIndex(“by_year”,“year”);}if(event.oldVersion <3){// Version 3 introduces a new object store for magazines with two indexes.const magazines = db.createObjectStore(“magazines”);const publisherIndex = magazines.createIndex(“by_publisher”,“publisher”);const frequencyIndex = magazines.createIndex(“by_frequency”,“frequency”);}}; request.onsuccess =function(){ db = request.result;// db.version will be 3.}; A single database can be used by multiple clients (pages and workers) simultaneously — transactions ensure they don’t clash while reading and writing. If a new client wants to upgrade the database (via the upgradeneeded event), it cannot do so until all other clients close their connection to the current version of the database. To avoid blocking a new client from upgrading, clients can listen for the versionchange event. This fires when another client is wanting to upgrade the database. To allow this to continue, react to the versionchange event by doing something that ultimately closes this client’s connection to the database.

One way of doing this is to reload the page:

db.onversionchange =function(){// First, save any unsaved data: saveUnsavedData().then(function(){// If the document isn’t being actively used, it could be appropriate to reload// the page without the user’s interaction.if(!document.hasFocus()){ location.reload();// Reloading will close the database, and also reload with the new JavaScript// and database definitions.}else{// If the document has focus, it can be too disruptive to reload the page.// Maybe ask the user to do it manually: displayMessage(“Please reload this page for the latest version.”);}});};function saveUnsavedData(){// How you do this depends on your app.}function displayMessage(){// Show a non-modal message to the user.}Another way is to call the connection’s close() method. However, you need to make sure your app is aware of this, as subsequent attempts to access the database will fail.

db.onversionchange =function(){ saveUnsavedData().then(function(){ db.close(); stopUsingTheDatabase();});};function stopUsingTheDatabase(){// Put the app into a state where it no longer uses the database.}The new client (the one attempting the upgrade) can use the blocked event to detect if other clients are preventing the upgrade from happening. The blocked event fires if other clients still hold a connection to the database after their versionchange events have fired.

const request = indexedDB.open(“library”,4);// Request version 4.let blockedTimeout; request.onblocked =function(){// Give the other clients time to save data asynchronously. blockedTimeout = setTimeout(function(){ displayMessage(“Upgrade blocked - Please close other tabs displaying this site.”);},1000);}; request.onupgradeneeded =function(event){ clearTimeout(blockedTimeout); hideMessage();// …};function hideMessage(){// Hide a previously displayed message.}The user will only see the above message if another client fails to disconnect from the database. Ideally the user will never see this.

2. Constructs

A name is a string equivalent to a DOMString; that is, an arbitrary sequence of 16-bit code units of any length, including the empty string. Names are always compared as opaque sequences of 16-bit code units.

NOTE: As a result, name comparison is sensitive to variations in case as well as other minor variations such as normalization form, the inclusion or omission of controls, and other variations in Unicode text. Charmod-NormIf an implementation uses a storage mechanism which does not support arbitrary strings, the implementation can use an escaping mechanism or something similar to map the provided name to a string that it can store.

To create a sorted name list from a listnames, run these steps:

  1. Let sorted be namessorted in ascending order with the code unit less than algorithm.
  2. Return a new DOMStringList associated with sorted. Details This matches the sort() method on an Array of String. This ordering compares the 16-bit code units in each string, producing a highly efficient, consistent, and deterministic sort order. The resulting list will not match any particular alphabet or lexicographical order, particularly for code points represented by a surrogate pair.

2.1. Database

Each storage key has an associated set of databases. A database has zero or more object stores which hold the data stored in the database.

A database has a name which identifies it within a specific storage key. The name is a name, and stays constant for the lifetime of the database.

A database has a version. When a database is first created, its version is 0 (zero).

NOTE: Each database has one version at a time; a database can’t exist in multiple versions at once. The only way to change the version is using an upgrade transaction.

A database has at most one associated upgrade transaction, which is either null or an upgrade transaction, and is initially null.

2.1.1. Database connection

Script does not interact with databases directly. Instead, script has indirect access via a connection. A connection object can be used to manipulate the objects of that database. It is also the only way to obtain a transaction for that database.

The act of opening a database creates a connection. There may be multiple connections to a given database at any given time.

A connection can only access databases associated with the storage key of the global scope from which the connection is opened.

NOTE: This is not affected by changes to the Document’s domain.

A connection has a version, which is set when the connection is created. It remains constant for the lifetime of the connection unless an upgrade is aborted, in which case it is set to the previous version of the database. Once the connection is closed the version does not change.

Each connection has a close pending flag which is initially false.

When a connection is initially created it is in an opened state. The connection can be closed through several means. If the execution context where the connection was created is destroyed (for example due to the user navigating away from that page), the connection is closed. The connection can also be closed explicitly using the steps to close a database connection. When the connection is closed its close pending flag is always set to true if it hasn’t already been.

A connection may be closed by a user agent in exceptional circumstances, for example due to loss of access to the file system, a permission change, or clearing of the storage key’s storage. If this occurs the user agent must run close a database connection with the connection and with the forced flag set to true.

A connection has an object store set, which is initialized to the set of object stores in the associated database when the connection is created. The contents of the set will remain constant except when an upgrade transaction is live.

A connection’s get the parent algorithm returns null.

An event with type versionchange will be fired at an open connection if an attempt is made to upgrade or delete the database. This gives the connection the opportunity to close to allow the upgrade or delete to proceed.

An event with type close will be fired at a connection if the connection is closed abnormally.

2.2. Object store

An object store is the primary storage mechanism for storing data in a database.

Each database has a set of object stores. The set of object stores can be changed, but only using an upgrade transaction, i.e. in response to an upgradeneeded event. When a new database is created it doesn’t contain any object stores.

An object store has a list of records which hold the data stored in the object store. Each record consists of a key and a value. The list is sorted according to key in ascending order. There can never be multiple records in a given object store with the same key.

An object store has a name, which is a name. At any one time, the name is unique within the database to which it belongs.

An object store optionally has a key path. If the object store has a key path it is said to use in-line keys. Otherwise it is said to use out-of-line keys.

An object store optionally has a key generator.

An object store can derive a key for a record from one of three sources:

  1. A key generator. A key generator generates a monotonically increasing numbers every time a key is needed.
  2. Keys can be derived via a key path.
  3. Keys can also be explicitly specified when a value is stored in the object store.

2.2.1. Object store handle

Script does not interact with object stores directly. Instead, within a transaction, script has indirect access via an object store handle.

An object store handle has an associated object store and an associated transaction. Multiple handles may be associated with the same object store in different transactions, but there must be only one object store handle associated with a particular object store within a transaction.

An object store handle has an index set, which is initialized to the set of indexes that reference the associated object store when the object store handle is created. The contents of the set will remain constant except when an upgrade transaction is live.

An object store handle has a name, which is initialized to the name of the associated object store when the object store handle is created. The name will remain constant except when an upgrade transaction is live.

2.3. Values

Each record is associated with a value. User agents must support any serializable object. This includes simple types such as String primitive values and Date objects as well as Object and Array instances, File objects, Blob objects, ImageData objects, and so on. Record values are stored and retrieved by value rather than by reference; later changes to a value have no effect on the record stored in the database.

Record values are Records output by the StructuredSerializeForStorage operation.

2.4. Keys

In order to efficiently retrieve records stored in an indexed database, each record is organized according to its key.

A key has an associated type which is one of: number, date, string, binary, or array.

A key also has an associated value, which will be either: an unrestricted double if type is number or date, a DOMString if type is string, a byte sequence if type is binary, or a list of other keys if type is array.

An ECMAScript ECMA-262 value can be converted to a key by following the steps to convert a value to a key.

NOTE: The following ECMAScript types are valid keys: - Number primitive values, except NaN. This includes Infinity and -Infinity.

  • Date objects, except where the DateValue internal slot is NaN.
  • String primitive values.
  • ArrayBuffer objects (or views on buffers such as Uint8Array).
  • Array objects, where every item is defined, is itself a valid key, and does not directly or indirectly contain itself. This includes empty arrays. Arrays can contain other arrays.

Attempting to convert other ECMAScript values to a key will fail.

An array key is a key with typearray. The subkeys of an array key are the items of the array key’s value.

To compare two keysa and b, run these steps:

  1. Let ta be the type of a.
  2. Let tb be the type of b.
  3. If ta does not equal tb, then run these steps:
  4. If ta is array, then return 1.
  5. If tb is array, then return -1.
  6. If ta is binary, then return 1.
  7. If tb is binary, then return -1.
  8. If ta is string, then return 1.
  9. If tb is string, then return -1.
  10. If ta is date, then return 1.
  11. Assert: tb is date.
  12. Return -1.
  13. Let va be the value of a.
  14. Let vb be the value of b.
  15. Switch on ta:

numberdate 1724. If va is greater than vb, then return 1. 1725. If va is less than vb, then return -1. 1726. Return 0. string1728. If va is code unit less thanvb, then return -1. 1729. If vb is code unit less thanva, then return 1. 1730. Return 0. binary1732. If va is byte less thanvb, then return -1. 1733. If vb is byte less thanva, then return 1. 1734. Return 0. array1736. Let length be the lesser of va’s size and vb’s size. 1737. Let i be 0. 1738. While i is less than length, then: 1739. Let c be the result of recursively comparing two keys with vai and vbi. 1740. If c is not 0, return c. 1741. Increase i by 1. 1742. If va’s size is greater than vb’s size, then return 1. 1743. If va’s size is less than vb’s size, then return -1. 1744. Return 0. The keya is greater than the keyb if the result of comparing two keys with a and b is 1.

The keya is less than the keyb if the result of comparing two keys with a and b is -1.

The keya is equal to the keyb if the result of comparing two keys with a and b is 0.

NOTE: As a result of the above rules, negative infinity is the lowest possible value for a key. Number keys are less than date keys. Date keys are less than string keys. String keys are less than binary keys. Binary keys are less than array keys. There is no highest possible key value. This is because an array of any candidate highest key followed by another key is even higher.

NOTE: Members of binary keys are compared as unsigned byte values (in the range 0 to 255 inclusive) rather than signed byte values (in the range -128 to 127 inclusive).

2.5. Key path

A key path is a string or list of strings that defines how to extract a key from a value. A valid key path is one of:

  • An empty string.
  • An identifier, which is a string matching the IdentifierName production from the ECMAScript Language Specification ECMA-262.
  • A string consisting of two or more identifiers separated by periods (U+002E FULL STOP).
  • A non-empty list containing only strings conforming to the above requirements.

NOTE: Spaces are not allowed within a key path.

Key path values can only be accessed from properties explicitly copied by StructuredSerializeForStorage, as well as the following type-specific properties:

Type Properties
Blob size, type
File name, lastModified
Array length
String length

2.6. Index

It is sometimes useful to retrieve records in an object store through other means than their key. An index allows looking up records in an object store using properties of the values in the object storesrecords.

An index is a specialized persistent key-value storage and has a referencedobject store. The index has a list of records which hold the data stored in the index. The records in an index are automatically populated whenever records in the referenced object store are inserted, updated or deleted. There can be several indexes referencing the same object store, in which changes to the object store cause all such indexes to get updated.

The values in the index’s records are always values of keys in the index’s referenced object store. The keys are derived from the referenced object store’s values using a key path. If a given record with key X in the object store referenced by the index has the value A, and evaluating the index’s key path on A yields the result Y, then the index will contain a record with key Y and value X.

For example, if an index’s referenced object store contains a record with the key 123 and the value { name: “Alice”, title: “CEO” }, and the index’s key path is “name” then the index would contain a record with the key “Alice” and the value 123. Records in an index are said to have a referenced value. This is the value of the record in the index’s referenced object store which has a key equal to the index’s record’s value. So in the example above, the record in the index whose key is Y and value is X has a referenced value of A.

In the preceding example, the record in the index with key “Alice” and value 123 would have a referenced value of { name: “Alice”, title: “CEO” }. NOTE: Each record in an index references one and only one record in the index’s referenced object store. However there can be multiple records in an index which reference the same record in the object store. And there can also be no records in an index which reference a given record in an object store.

The records in an index are always sorted according to the record’s key. However unlike object stores, a given index can contain multiple records with the same key. Such records are additionally sorted according to the index’s record’s value (meaning the key of the record in the referenced object store).

An index has a name, which is a name. At any one time, the name is unique within index’s referencedobject store.

An index has a unique flag. When true, the index enforces that no two records in the index has the same key. If a record in the index’s referenced object store is attempted to be inserted or modified such that evaluating the index’s key path on the records new value yields a result which already exists in the index, then the attempted modification to the object store fails.

An index has a multiEntry flag. This flag affects how the index behaves when the result of evaluating the index’s key path yields an array key. If its multiEntry flag is false, then a single record whose key is an array key is added to the index. If its multiEntry flag is true, then one record is added to the index for each of the subkeys.

2.6.1. Index handle

Script does not interact with indexes directly. Instead, within a transaction, script has indirect access via an index handle.

An index handle has an associated index and an associated object store handle. The transaction of an index handle is the transaction of its associated object store handle. Multiple handles may be associated with the same index in different transactions, but there must be only one index handle associated with a particular index within a transaction.

An index handle has a name, which is initialized to the name of the associated index when the index handle is created. The name will remain constant except when an upgrade transaction is live.

2.7. Transactions

A transaction is used to interact with the data in a database. Whenever data is read or written to the database it is done by using a transaction.

Transactions offer some protection from application and system failures. A transaction may be used to store multiple data records or to conditionally modify certain data records. A transaction represents an atomic and durable set of data access and data mutation operations.

All transactions are created through a connection, which is the transaction’s connection.

A transaction has a scope which is a set of object stores that the transaction may interact with.

NOTE: A transaction’s scope remains fixed unless the transaction is an upgrade transaction.

Two transactions have overlapping scope if any object store is in both transactions’ scope.

A transaction has a mode that determines which types of interactions can be performed upon that transaction. The mode is set when the transaction is created and remains fixed for the life of the transaction. A transaction’s mode is one of the following:

“readonly” The transaction is only allowed to read data. No modifications can be done by this type of transaction. This has the advantage that several read-only transactions can be started at the same time even if their scopes are overlapping, i.e. if they are using the same object stores. This type of transaction can be created any time once a database has been opened.

“readwrite” The transaction is allowed to read, modify and delete data from existing object stores. However object stores and indexes can’t be added or removed. Multiple “readwrite” transactions can’t be started at the same time if their scopes are overlapping since that would mean that they can modify each other’s data in the middle of the transaction. This type of transaction can be created any time once a database has been opened.

“versionchange” The transaction is allowed to read, modify and delete data from existing object stores, and can also create and remove object stores and indexes. It is the only type of transaction that can do so. This type of transaction can’t be manually created, but instead is created automatically when an upgradeneeded event is fired.

A transaction has a durability hint. This is a hint to the user agent of whether to prioritize performance or durability when committing the transaction. The durability hint is one of the following:

“strict” The user agent may consider that the transaction has successfully committed only after verifying that all outstanding changes have been successfully written to a persistent storage medium.

“relaxed” The user agent may consider that the transaction has successfully committed as soon as all outstanding changes have been written to the operating system, without subsequent verification.

“default” The user agent should use its default durability behavior for the storage bucket. This is the default for transactions if not otherwise specified.

NOTE: In a typical implementation, “strict” is a hint to the user agent to flush any operating system I/O buffers before a complete event is fired. While this provides greater confidence that the changes will be persisted in case of subsequent operating system crash or power loss, flushing buffers can take significant time and consume battery life on portable devices. Web applications are encouraged to use “relaxed” for ephemeral data such as caches or quickly changing records, and “strict” in cases where reducing the risk of data loss outweighs the impact to performance and power. Implementations are encouraged to weigh the durability hint from applications against the impact to users and devices.

A transaction optionally has a cleanup event loop which is an event loop.

A transaction has a request list of pending requests which have been made against the transaction.

A transaction has a error which is set if the transaction is aborted.

A transaction’s get the parent algorithm returns the transaction’s connection.

A read-only transaction is a transaction with mode “readonly”.

A read/write transaction is a transaction with mode “readwrite”.

2.7.1. Transaction lifecycle

A transaction has a state, which is one of the following:

activeA transaction is in this state when it is first created, and during dispatch of an event from a request associated with the transaction.

New requests can be made against the transaction when it is in this state.

inactiveA transaction is in this state after control returns to the event loop after its creation, and when events are not being dispatched.

No requests can be made against the transaction when it is in this state.

committingOnce all requests associated with a transaction have completed, the transaction will enter this state as it attempts to commit.

No requests can be made against the transaction when it is in this state.

finishedOnce a transaction has committed or aborted, it enters this state.

No requests can be made against the transaction when it is in this state.

Transactions are expected to be short lived. This is encouraged by the automatic committing functionality described below.

NOTE: Authors can still cause transactions to stay alive for a long time; however, this usage pattern is not advised as it can lead to a poor user experience.

The lifetime of a transaction is as follows:

  1. A transaction is created with a scope and a mode. When a transaction is created its state is initially active.
  2. When an implementation is able to enforce the constraints for the transaction’s scope and mode, defined below, the implementation must queue a task to start the transaction asynchronously.

Once the transaction has been started the implementation can begin executing the requests placed against the transaction. Requests must be executed in the order in which they were made against the transaction. Likewise, their results must be returned in the order the requests were placed against a specific transaction. There is no guarantee about the order that results from requests in different transactions are returned.

NOTE: Transaction modes ensure that two requests placed against different transactions can execute in any order without affecting what resulting data is stored in the database. 1821. When each request associated with a transaction is processed, a success or errorevent will be fired. While the event is being dispatched, the transaction state is set to active, allowing additional requests to be made against the transaction. Once the event dispatch is complete, the transaction’s state is set to inactive again. 1822. A transaction can be aborted at any time before it is finished, even if the transaction isn’t currently active or hasn’t yet started.

An explicit call to abort() will initiate an abort. An abort will also be initiated following a failed request that is not handled by script.

When a transaction is aborted the implementation must undo (roll back) any changes that were made to the database during that transaction. This includes both changes to the contents of object stores as well as additions and removals of object stores and indexes. 1823. The implementation must attempt to commit a transaction when all requests placed against the transaction have completed and their returned results handled, no new requests have been placed against the transaction, and the transaction has not been aborted

An explicit call to commit() will initiate a commit without waiting for request results to be handled by script.

When committing, the transaction state is set to committing. The implementation must atomically write any changes to the database made by requests placed against the transaction. That is, either all of the changes must be written, or if an error occurs, such as a disk write error, the implementation must not write any of the changes to the database, and the steps to abort a transaction will be followed. 1824. When a transaction is committed or aborted, its state is set to finished. The implementation must allow requests to be placed against the transaction whenever it is active. This is the case even if the transaction has not yet been started. Until the transaction is started the implementation must not execute these requests; however, the implementation must keep track of the requests and their order.

A transaction is said to be live from when it is created until its state is set to finished.

To cleanup Indexed Database transactions, run the following steps. They will return true if any transactions were cleaned up, or false otherwise.

  1. If there are no transactions with cleanup event loop matching the current event loop, return false.
  2. For each transactiontransaction with cleanup event loop matching the current event loop:
  3. Set transaction’s state to inactive.
  4. Clear transaction’s cleanup event loop.
  5. Return true. NOTE: These steps are invoked by HTML. They ensure that transactions created by a script call to transaction() are deactivated once the task that invoked the script has completed. The steps are run at most once for each transaction.

An event with type complete is fired at a transaction that has successfully committed.

An event with type abort is fired at a transaction that has aborted.

2.7.2. Transaction scheduling

The following constraints define when a transaction can be started:

  • A read-only transactionstx can start when there are no read/write transactions which:

  • Were created before tx; and

  • have overlapping scopes with tx; and

  • are not finished.

  • A read/write transactiontx can start when there are no transactions which:

  • Were created before tx; and

  • have overlapping scopes with tx; and

  • are not finished.

Implementations may impose additional constraints. For example, implementations are not required to start non-overlappingread/write transactions in parallel, or may impose limits on the number of started transactions.

NOTE: These constraints imply the following: - Any number of read-only transactions are allowed to be started concurrently, even if they have overlapping scopes.

  • As long as a read-only transaction is live, the data that the implementation returns through requests created with that transaction remains constant. That is, two requests to read the same piece of data yield the same result both for the case when data is found and the result is that data, and for the case when data is not found and a lack of data is indicated.
  • A read/write transaction is only affected by changes to object stores that are made using the transaction itself. The implementation ensures that another transaction does not modify the contents of object stores in the read/write transaction’s scope. The implementation also ensures that if the read/write transaction completes successfully, the changes written to object stores using the transaction can be committed to the database without merge conflicts.
  • If multiple read/write transactions are attempting to access the same object store (i.e. if they have overlapping scopes), the transaction that was created first is the transaction which gets access to the object store first, and it is the only transaction which has access to the object store until the transaction is finished.
  • Any transaction created after a read/write transaction sees the changes written by the read/write transaction. For example, if a read/write transaction A, is created, and later another transaction B, is created, and the two transactions have overlapping scopes, then transaction B sees any changes made to any object stores that are part of that overlapping scope. This also means that transaction B does not have access to any object stores in that overlapping scope until transaction A is finished.

A transaction has a state, which is one of the following:

activeA transaction is in this state when it is first created, and during dispatch of an event from a request associated with the transaction.

New requests can be made against the transaction when it is in this state.

inactiveA transaction is in this state after control returns to the event loop after its creation, and when events are not being dispatched.

No requests can be made against the transaction when it is in this state.

committingOnce all requests associated with a transaction have completed, the transaction will enter this state as it attempts to commit.

No requests can be made against the transaction when it is in this state.

finishedOnce a transaction has committed or aborted, it enters this state.

No requests can be made against the transaction when it is in this state.

Transactions are expected to be short lived. This is encouraged by the automatic committing functionality described below.

NOTE: Authors can still cause transactions to stay alive for a long time; however, this usage pattern is not advised as it can lead to a poor user experience.

The lifetime of a transaction is as follows:

  1. A transaction is created with a scope and a mode. When a transaction is created its state is initially active.
  2. When an implementation is able to enforce the constraints for the transaction’s scope and mode, defined below, the implementation must queue a task to start the transaction asynchronously.

Once the transaction has been started the implementation can begin executing the requests placed against the transaction. Requests must be executed in the order in which they were made against the transaction. Likewise, their results must be returned in the order the requests were placed against a specific transaction. There is no guarantee about the order that results from requests in different transactions are returned.

NOTE: Transaction modes ensure that two requests placed against different transactions can execute in any order without affecting what resulting data is stored in the database. 1861. When each request associated with a transaction is processed, a success or errorevent will be fired. While the event is being dispatched, the transaction state is set to active, allowing additional requests to be made against the transaction. Once the event dispatch is complete, the transaction’s state is set to inactive again. 1862. A transaction can be aborted at any time before it is finished, even if the transaction isn’t currently active or hasn’t yet started.

An explicit call to abort() will initiate an abort. An abort will also be initiated following a failed request that is not handled by script.

When a transaction is aborted the implementation must undo (roll back) any changes that were made to the database during that transaction. This includes both changes to the contents of object stores as well as additions and removals of object stores and indexes. 1863. The implementation must attempt to commit a transaction when all requests placed against the transaction have completed and their returned results handled, no new requests have been placed against the transaction, and the transaction has not been aborted

An explicit call to commit() will initiate a commit without waiting for request results to be handled by script.

When committing, the transaction state is set to committing. The implementation must atomically write any changes to the database made by requests placed against the transaction. That is, either all of the changes must be written, or if an error occurs, such as a disk write error, the implementation must not write any of the changes to the database, and the steps to abort a transaction will be followed. 1864. When a transaction is committed or aborted, its state is set to finished. The implementation must allow requests to be placed against the transaction whenever it is active. This is the case even if the transaction has not yet been started. Until the transaction is started the implementation must not execute these requests; however, the implementation must keep track of the requests and their order.

A transaction is said to be live from when it is created until its state is set to finished.

To cleanup Indexed Database transactions, run the following steps. They will return true if any transactions were cleaned up, or false otherwise.

  1. If there are no transactions with cleanup event loop matching the current event loop, return false.
  2. For each transactiontransaction with cleanup event loop matching the current event loop:
  3. Set transaction’s state to inactive.
  4. Clear transaction’s cleanup event loop.
  5. Return true. NOTE: These steps are invoked by HTML. They ensure that transactions created by a script call to transaction() are deactivated once the task that invoked the script has completed. The steps are run at most once for each transaction.

An event with type complete is fired at a transaction that has successfully committed.

An event with type abort is fired at a transaction that has aborted.

2.7.2. Transaction scheduling

The following constraints define when a transaction can be started:

  • A read-only transactionstx can start when there are no read/write transactions which:

  • Were created before tx; and

  • have overlapping scopes with tx; and

  • are not finished.

  • A read/write transactiontx can start when there are no transactions which:

  • Were created before tx; and

  • have overlapping scopes with tx; and

  • are not finished.

Implementations may impose additional constraints. For example, implementations are not required to start non-overlappingread/write transactions in parallel, or may impose limits on the number of started transactions.

NOTE: These constraints imply the following: - Any number of read-only transactions are allowed to be started concurrently, even if they have overlapping scopes.

  • As long as a read-only transaction is live, the data that the implementation returns through requests created with that transaction remains constant. That is, two requests to read the same piece of data yield the same result both for the case when data is found and the result is that data, and for the case when data is not found and a lack of data is indicated.
  • A read/write transaction is only affected by changes to object stores that are made using the transaction itself. The implementation ensures that another transaction does not modify the contents of object stores in the read/write transaction’s scope. The implementation also ensures that if the read/write transaction completes successfully, the changes written to object stores using the transaction can be committed to the database without merge conflicts.
  • If multiple read/write transactions are attempting to access the same object store (i.e. if they have overlapping scopes), the transaction that was created first is the transaction which gets access to the object store first, and it is the only transaction which has access to the object store until the transaction is finished.
  • Any transaction created after a read/write transaction sees the changes written by the read/write transaction. For example, if a read/write transaction A, is created, and later another transaction B, is created, and the two transactions have overlapping scopes, then transaction B sees any changes made to any object stores that are part of that overlapping scope. This also means that transaction B does not have access to any object stores in that overlapping scope until transaction A is finished.

2.7.3. Upgrade transactions

An upgrade transaction is a transaction with mode “versionchange”.

An upgrade transaction is automatically created when running the steps to upgrade a database after a connection is opened to a database, if a version greater than the current version is specified. This transaction will be active inside the upgradeneeded event handler.

NOTE: An upgrade transaction enables the creation, renaming, and deletion of object stores and indexes in a database. An upgrade transaction is exclusive. The steps to open a database connection ensure that only one connection to the database is open when an upgrade transaction is live. The upgradeneeded event isn’t fired, and thus the upgrade transaction isn’t started, until all other connections to the same database are closed. This ensures that all previous transactions are finished.

As long as an upgrade transaction is live, attempts to open more connections to the same database are delayed, and any attempts to use the same connection to start additional transactions by calling transaction() will throw an exception. This ensures that no other transactions are live concurrently, and also ensures that no new transactions are queued against the same database as long as the upgrade transaction is live.

This further ensures that once an upgrade transaction is complete, the set of object stores and indexes in a database remain constant for the lifetime of all subsequent connections and transactions.

2.8. Requests

Each asynchronous operation on a database is done using a request. Every request represents one operation.

A request has a processed flag which is initially false. This flag is set to true when the operation associated with the request has been executed.

A request is said to be processed when its processed flag is true.

A request has a done flag which is initially false. This flag is set to true when the result of the operation associated with the request is available.

A request has a source object.

A request has a result and an error, neither of which are accessible until its done flag is true.

A request has a transaction which is initially null. This will be set when a request is placed against a transaction using the steps to asynchronously execute a request.

When a request is made, a new request is returned with its done flag set to false. If a request completes successfully, its done flag is set to true, its result is set to the result of the request, and an event with type success is fired at the request.

If an error occurs while performing the operation, the request’s done flag is set to true, the request’s error is set to the error, and an event with type error is fired at the request.

A request’s get the parent algorithm returns the request’s transaction.

NOTE: Requests are not typically re-used, but there are exceptions. When a cursor is iterated, the success of the iteration is reported on the same request object used to open the cursor. And when an upgrade transaction is necessary, the same open request is used for both the upgradeneeded event and final result of the open operation itself. In some cases, the request’s done flag will be set to false, then set to true again, and the result can change or error could be set instead.

2.8.1. Open requests

An open request is a special type of request used when opening a connection or deleting a database. In addition to success and error events, blocked and upgradeneeded events may be fired at an open request to indicate progress.

The source of an open request is always null.

The transaction of an open request is null unless an upgradeneeded event has been fired.

An open request’s get the parent algorithm returns null.

An open request is a special type of request used when opening a connection or deleting a database. In addition to success and error events, blocked and upgradeneeded events may be fired at an open request to indicate progress.

The source of an open request is always null.

The transaction of an open request is null unless an upgradeneeded event has been fired.

An open request’s get the parent algorithm returns null.

2.8.2. Connection queues

Open requests are processed in a connection queue. The queue contains all open requests associated with an storage key and a name. Requests added to the connection queue processed in order and each request must run to completion before the next request is processed. An open request may be blocked on other connections, requiring those connections to close before the request can complete and allow further requests to be processed.

NOTE: A connection queue is not a task queue associated with an event loop, as the requests are processed outside any specific browsing context. The delivery of events to completed open request still goes through a task queue associated with the event loop of the context where the request was made.

2.9. Key range

Records can be retrieved from object stores and indexes using either keys or key ranges. A key range is a continuous interval over some data type used for keys.

A key range has an associated lower bound (null or a key).

A key range has an associated upper bound (null or a key).

A key range has an associated lower open flag. Unless otherwise stated it is false.

A key range has an associated upper open flag. Unless otherwise stated it is false.

A key range may have a lower boundequal to its upper bound. A key range must not have a lower boundgreater than its upper bound.

A key rangecontaining onlykey has both lower bound and upper bound equal to key.

A key is in a key rangerange if both of the following conditions are fulfilled:

  • The range’s lower bound is null, or it is less thankey, or it is both equal tokey and the range’s lower open flag is false.
  • The range’s upper bound is null, or it is greater thankey, or it is both equal tokey and the range’s upper open flag is false.

NOTE:- If a key range’s lower open flag is false, the lower boundkey of the key range is included in the range itself.

  • If a key range’s lower open flag is true, the lower boundkey of the key range is excluded from the range itself.
  • If a key range’s upper open flag is false, the upper boundkey of the key range is included in the range itself.
  • If a key range’s upper open flag is true, the upper boundkey of the key range is excluded from the range itself.

An unbounded key range is a key range that has both lower bound and upper bound equal to null. All keys are in an unbounded key range.

To convert a value to a key range with value and optional null disallowed flag, run these steps:

  1. If value is a key range, return value.
  2. If value is undefined or is null, then throw a “DataError” DOMException if null disallowed flag is true, or return an unbounded key range otherwise.
  3. Let key be the result of converting a value to a key with value. Rethrow any exceptions.
  4. If key is invalid, throw a “DataError” DOMException.
  5. Return a key rangecontaining onlykey.

2.10. Cursor

A cursor is used to iterate over a range of records in an index or an object store in a specific direction.

A cursor has a transaction, the transaction that was active when the cursor was created.

A cursor has a range of records in either an index or an object store.

A cursor has a source that indicates which index or an object store is associated with the records over which the cursor is iterating.

A cursor has a direction that determines whether it moves in monotonically increasing or decreasing order of the record keys when iterated, and if it skips duplicated values when iterating indexes. The direction of a cursor also determines if the cursor initial position is at the start of its source or at its end. A cursor’s direction is one of the following:

“next” This direction causes the cursor to be opened at the start of the source. When iterated, the cursor should yield all records, including duplicates, in monotonically increasing order of keys.

“nextunique” This direction causes the cursor to be opened at the start of the source. When iterated, the cursor should not yield records with the same key, but otherwise yield all records, in monotonically increasing order of keys. For every key with duplicate values, only the first record is yielded. When the source is an object store or an index with its unique flag set to true, this direction has exactly the same behavior as “next”.

“prev” This direction causes the cursor to be opened at the end of the source. When iterated, the cursor should yield all records, including duplicates, in monotonically decreasing order of keys.

“prevunique” This direction causes the cursor to be opened at the end of the source. When iterated, the cursor should not yield records with the same key, but otherwise yield all records, in monotonically decreasing order of keys. For every key with duplicate values, only the first record is yielded. When the source is an object store or an index with its unique flag set to true, this direction has exactly the same behavior as “prev”.

A cursor has a position within its range. It is possible for the list of records which the cursor is iterating over to change before the full range of the cursor has been iterated. In order to handle this, cursors maintain their position not as an index, but rather as a key of the previously returned record. For a forward iterating cursor, the next time the cursor is asked to iterate to the next record it returns the record with the lowest keygreater than the one previously returned. For a backwards iterating cursor, the situation is opposite and it returns the record with the highest keyless than the one previously returned.

For cursors iterating indexes the situation is a little bit more complicated since multiple records can have the same key and are therefore also sorted by value. When iterating indexes the cursor also has an object store position, which indicates the value of the previously found record in the index. Both position and the object store position are used when finding the next appropriate record.

A cursor has a key and a value which represent the key and the value of the last iterated record.

A cursor has a got value flag. When this flag is false, the cursor is either in the process of loading the next value or it has reached the end of its range. When it is true, it indicates that the cursor is currently holding a value and that it is ready to iterate to the next one.

If the source of a cursor is an object store, the effective object store of the cursor is that object store and the effective key of the cursor is the cursor’s position. If the source of a cursor is an index, the effective object store of the cursor is that index’s referenced object store and the effective key is the cursor’s object store position.

A cursor has a request, which is the request used to open the cursor.

A cursor also has a key only flag, that indicates whether the cursor’s value is exposed via the API.

2.11. Key generators

When a object store is created it can be specified to use a key generator. A key generator is used to generate keys for records inserted into an object store if not otherwise specified.

A key generator has a current number. The current number is always a positive integer less than or equal to 253 (9007199254740992) + 1. The initial value of a key generator’s current number is 1, set when the associated object store is created. The current number is incremented as keys are generated, and may be updated to a specific value by using explicit keys.

NOTE: Every object store that uses key generators uses a separate generator. That is, interacting with one object store never affects the key generator of any other object store.

Modifying a key generator’s current number is considered part of a database operation. This means that if the operation fails and the operation is reverted, the current number is reverted to the value it had before the operation started. This applies both to modifications that happen due to the current number getting increased by 1 when the key generator is used, and to modifications that happen due to a record being stored with a key value specified in the call to store the record.

Likewise, if a transaction is aborted, the current number of the key generator for each object store in the transaction’s scope is reverted to the value it had before the transaction was started.

The current number for a key generator never decreases, other than as a result of database operations being reverted. Deleting a record from an object store never affects the object store’s key generator. Even clearing all records from an object store, for example using the clear() method, does not affect the current number of the object store’s key generator.

When a record is stored and a key is not specified in the call to store the record, a key is generated.

To generate a key for an object storestore, run these steps:

  1. Let generator be store’s key generator.
  2. Let key be generator’s current number.
  3. If key is greater than 253 (9007199254740992), then return failure.
  4. Increase generator’s current number by 1.
  5. Return key. When a record is stored and a key is specified in the call to store the record, the associated key generator may be updated.

To possibly update the key generator for an object storestore with key, run these steps:

  1. If the type of key is not number, abort these steps.
  2. Let value be the value of key.
  3. Set value to the minimum of value and 253 (9007199254740992).
  4. Set value to the largest integer not greater than value.
  5. Let generator be store’s key generator.
  6. If value is greater than or equal to generator’s current number, then set generator’s current number to value + 1. NOTE: A key can be specified both for object stores which use in-line keys, by setting the property on the stored value which the object store’s key path points to, and for object stores which use out-of-line keys, by passing a key argument to the call to store the record. Only specified keys of typenumber can affect the current number of the key generator. Keys of typedate, array (regardless of the other keys they contain), binary, or string (regardless of whether they could be parsed as numbers) have no effect on the current number of the key generator. Keys of typenumber with value less than 1 do not affect the current number since they are always lower than the current number.

When the current number of a key generator reaches above the value 253 (9007199254740992) any subsequent attempts to use the key generator to generate a new key will result in a “ConstraintError” DOMException. It is still possible to insert records into the object store by specifying an explicit key, however the only way to use a key generator again for such records is to delete the object store and create a new one.

NOTE: This limit arises because integers greater than 9007199254740992 cannot be uniquely represented as ECMAScript Numbers. As an example, 9007199254740992 + 1 === 9007199254740992 in ECMAScript. As long as key generators are used in a normal fashion this limit will not be a problem. If you generate a new key 1000 times per second day and night, you won’t run into this limit for over 285000 years.

A practical result of this is that the first key generated for an object store is always 1 (unless a higher numeric key is inserted first) and the key generated for an object store is always a positive integer higher than the highest numeric key in the store. The same key is never generated twice for the same object store unless a transaction is rolled back.

Each object store gets its own key generator:

store1 = db.createObjectStore(“store1”,{ autoIncrement:true}); store1.put(“a”);// Will get key 1 store2 = db.createObjectStore(“store2”,{ autoIncrement:true}); store2.put(“a”);// Will get key 1 store1.put(“b”);// Will get key 2 store2.put(“b”);// Will get key 2If an insertion fails due to constraint violations or IO error, the key generator is not updated.

transaction.onerror =function(e){ e.preventDefault()}; store = db.createObjectStore(“store1”,{ autoIncrement:true}); index = store.createIndex(“index1”,“ix”,{ unique:true}); store.put({ ix:“a”});// Will get key 1 store.put({ ix:“a”});// Will fail store.put({ ix:“b”});// Will get key 2Removing items from an objectStore never affects the key generator. Including when clear() is called.

store = db.createObjectStore(“store1”,{ autoIncrement:true}); store.put(“a”);// Will get key 1 store.delete(1); store.put(“b”);// Will get key 2 store.clear(); store.put(“c”);// Will get key 3 store.delete(IDBKeyRange.lowerBound(0)); store.put(“d”);// Will get key 4Inserting an item with an explicit key affects the key generator if, and only if, the key is numeric and higher than the last generated key.

store = db.createObjectStore(“store1”,{ autoIncrement:true}); store.put(“a”);// Will get key 1 store.put(“b”,3);// Will use key 3 store.put(“c”);// Will get key 4 store.put(“d”,-10);// Will use key -10 store.put(“e”);// Will get key 5 store.put(“f”,6.00001);// Will use key 6.0001 store.put(“g”);// Will get key 7 store.put(“f”,8.9999);// Will use key 8.9999 store.put(“g”);// Will get key 9 store.put(“h”,“foo”);// Will use key “foo” store.put(“i”);// Will get key 10 store.put(“j”,1000);// Will use key 1000 store.put(“k”);// Will get key 11// All of these would behave the same if the objectStore used a// keyPath and the explicit key was passed inline in the objectAborting a transaction rolls back any increases to the key generator which happened during the transaction. This is to make all rollbacks consistent since rollbacks that happen due to crash never has a chance to commit the increased key generator value.

db.createObjectStore(“store”,{ autoIncrement:true}); trans1 = db.transaction(“store”,“readwrite”); store_t1 = trans1.objectStore(“store”); store_t1.put(“a”);// Will get key 1 store_t1.put(“b”);// Will get key 2 trans1.abort(); trans2 = db.transaction(“store”,“readwrite”); store_t2 = trans2.objectStore(“store”); store_t2.put(“c”);// Will get key 1 store_t2.put(“d”);// Will get key 2 The following examples illustrate the different behaviors when trying to use in-line keys and key generators to save an object to an object store.

If the following conditions are true:

  • The object store has a key generator.
  • There is no in-line value for the key path property.

Then the value provided by the key generator is used to populate the key value. In the example below the key path for the object store is “foo.bar”. The actual object has no value for the bar property, { foo: {} }. When the object is saved in the object store the bar property is assigned a value of 1 because that is the next key generated by the key generator.

const store = db.createObjectStore(“store”,{ keyPath:“foo.bar”, autoIncrement:true}); store.put({ foo:{}}).onsuccess =function(e){const key = e.target.result; console.assert(key ===1);};If the following conditions are true:

  • The object store has a key generator.
  • There is a value for the key path property.

Then the value associated with the key path property is used. The auto-generated key is not used. In the example below the key path for the object store is “foo.bar”. The actual object has a value of 10 for the bar property, { foo: { bar: 10} }. When the object is saved in the object store the bar property keeps its value of 10, because that is the key value.

const store = db.createObjectStore(“store”,{ keyPath:“foo.bar”, autoIncrement:true}); store.put({ foo:{ bar:10}}).onsuccess =function(e){const key = e.target.result; console.assert(key ===10);};The following example illustrates the scenario when the specified in-line key is defined through a key path but there is no property matching it. The value provided by the key generator is then used to populate the key value and the system is responsible for creating as many properties as it requires to suffice the property dependencies on the hierarchy chain. In the example below the key path for the object store is “foo.bar.baz”. The actual object has no value for the foo property, { zip: {} }. When the object is saved in the object store the foo, bar, and baz properties are created each as a child of the other until a value for foo.bar.baz can be assigned. The value for foo.bar.baz is the next key generated by the object store.

const store = db.createObjectStore(“store”,{ keyPath:“foo.bar.baz”, autoIncrement:true}); store.put({ zip:{}}).onsuccess =function(e){const key = e.target.result; console.assert(key ===1); store.get(key).onsuccess =function(e){const value = e.target.result;// value will be: { zip: {}, foo: { bar: { baz: 1 } } } console.assert(value.foo.bar.baz ===1);};};Attempting to store a property on a primitive value will fail and throw an error. In the first example below the key path for the object store is “foo”. The actual object is a primitive with the value, 4. Trying to define a property on that primitive value fails. The same is true for arrays. Properties are not allowed on an array. In the second example below, the actual object is an array, 10. Trying to define a property on the array fails.

const store = db.createObjectStore(“store”,{ keyPath:“foo”, autoIncrement:true});// The key generation will attempt to create and store the key path// property on this primitive. store.put(4);// will throw DataError// The key generation will attempt to create and store the key path// property on this array. store.put(10);// will throw DataError

3. Exceptions

Each of the exceptions used in this document is a DOMException with a specific type. The exception types and properties such as legacy code value are defined in WEBIDL.

The table below lists the DOMExceptions used in this document along with a description of the exception type’s usage.

Type Description
AbortError A request was aborted.
ConstraintError A mutation operation in the transaction failed because a constraint was not satisfied.
DataCloneError The data being stored could not be cloned by the internal structured cloning algorithm.
DataError Data provided to an operation does not meet requirements.
InvalidAccessError An invalid operation was performed on an object.
InvalidStateError An operation was called on an object on which it is not allowed or at a time when it is not allowed, or if a request is made on a source object that has been deleted or removed.
NotFoundError The operation failed because the requested database object could not be found.
NotReadableError The operation failed because the underlying storage containing the requested data could not be read.
QuotaExceededError The operation failed because there was not enough remaining storage space, or the storage quota was reached and the user declined to give more space to the database.
SyntaxError The keyPath argument contains an invalid key path.
ReadOnlyError The mutating operation was attempted in a read-only transaction.
TransactionInactiveError A request was placed against a transaction which is currently not active, or which is finished.
UnknownError The operation failed for transient reasons unrelated to the database itself or not covered by any other error.
VersionError An attempt was made to open a database using a lower version than the existing version.

NOTE: Given that multiple Indexed DB operations can throw the same type of error, and that even a single operation can throw the same type of error for multiple reasons, implementations are encouraged to provide more specific messages to enable developers to identify the cause of errors.

4. API

The API methods return without blocking the calling thread. All asynchronous operations immediately return an IDBRequest instance. This object does not initially contain any information about the result of the operation. Once information becomes available, an event is fired on the request and the information becomes available through the properties of the IDBRequest instance.

The task source for these tasks is the database access task source.

4.1. The IDBRequest interface

The IDBRequest interface provides the means to access results of asynchronous requests to databases and database objects using event handler IDL attributesHTML.

Every method for making asynchronous requests returns an IDBRequest object that communicates back to the requesting application through events. This design means that any number of requests can be active on any database at a time.

In the following example, we open a database asynchronously. Various event handlers are registered for responding to various situations.

const request = indexedDB.open(‘AddressBook’,15); request.onsuccess =function(evt){…}; request.onerror =function(evt){…}; Exposed=(Window,Worker) interfaceIDBRequest : EventTarget { readonlyattributeanyresult; readonlyattributeDOMException? error; readonlyattribute (IDBObjectStoreorIDBIndexorIDBCursor)? source; readonlyattributeIDBTransaction? transaction; readonlyattributeIDBRequestReadyStatereadyState; // Event handlers: attributeEventHandleronsuccess; attributeEventHandleronerror; }; enumIDBRequestReadyState { “pending”, “done” }; request . resultWhen a request is completed, returns the result, or undefined if the request failed. Throws a “InvalidStateError” DOMException if the request is still pending.

request . errorWhen a request is completed, returns the error (a DOMException), or null if the request succeeded. Throws a “InvalidStateError” DOMException if the request is still pending.

request . sourceReturns the IDBObjectStore, IDBIndex, or IDBCursor the request was made against, or null if it was an open request.

request . transactionReturns the IDBTransaction the request was made within. If this as an open request, then it returns an upgrade transaction while it is live, or null otherwise.

request . readyStateReturns “pending” until a request is complete, then returns “done”.

The result getter steps are: 2031. If this’s done flag is false, then throw an “InvalidStateError” DOMException. 2032. Otherwise, return this’s result, or undefined if the request resulted in an error.

The error getter steps are: 2034. If this’s done flag is false, then throw an “InvalidStateError” DOMException. 2035. Otherwise, return this’s error, or null if no error occurred. The source getter steps are to return this’s source, or null if no source is set.

The transaction getter steps are to return this’s transaction.

NOTE: The transaction getter can return null for certain requests, such as for requests returned from open().

The readyState getter steps are to return “pending” if this’s done flag is false, and “done” otherwise.

The onsuccess attribute is an event handler IDL attribute whose event handler event type is success.

The onerror attribute is an event handler IDL attribute whose event handler event type is error event.

Methods on IDBDatabase that return a open request use an extended interface to allow listening to the blocked and upgradeneeded events.

Exposed=(Window,Worker) interfaceIDBOpenDBRequest : IDBRequest { // Event handlers: attributeEventHandleronblocked; attributeEventHandleronupgradeneeded; }; The onblocked attribute is an event handler IDL attribute whose event handler event type is blocked.

The onupgradeneeded attribute is an event handler IDL attribute whose event handler event type is upgradeneeded.

4.2. Event interfaces

This specification fires events with the following custom interfaces:

Exposed=(Window,Worker) interfaceIDBVersionChangeEvent : Event { constructor(DOMStringtype, optionalIDBVersionChangeEventIniteventInitDict = {}); readonlyattributeunsignedlonglongoldVersion; readonlyattributeunsignedlonglong? newVersion; }; dictionaryIDBVersionChangeEventInit : EventInit { unsignedlonglongoldVersion = 0; unsignedlonglong? newVersion = null; }; The oldVersion getter steps are to return the value it was initialized to. It represents the previous version of the database.

The newVersion getter steps are to return the value it was initialized to. It represents the new version of the database, or null if the database is being deleted. See the steps to upgrade a database.

Events are constructed as defined in DOM § 2.5 Constructing events.

To fire a version change event named e at target given oldVersion and newVersion, run these steps:

  1. Let event be the result of creating an event using IDBVersionChangeEvent.
  2. Set event’s type attribute to e.
  3. Set event’s bubbles and cancelable attributes to false.
  4. Set event’s oldVersion attribute to oldVersion.
  5. Set event’s newVersion attribute to newVersion.
  6. Let legacyOutputDidListenersThrowFlag be false.
  7. Dispatchevent at target with legacyOutputDidListenersThrowFlag.
  8. Return legacyOutputDidListenersThrowFlag.

NOTE: The return value of this algorithm is not always used.

4.3. The IDBFactory interface

Database objects are accessed through methods on the IDBFactory interface. A single object implementing this interface is present in the global scope of environments that support Indexed DB operations.

partialinterfacemixinWindowOrWorkerGlobalScope { SameObject readonlyattributeIDBFactoryindexedDB; }; The indexedDB attribute provides applications a mechanism for accessing capabilities of indexed databases.

Exposed=(Window,Worker) interfaceIDBFactory { NewObject IDBOpenDBRequestopen(DOMStringname, optional EnforceRange unsignedlonglongversion); NewObject IDBOpenDBRequestdeleteDatabase(DOMStringname); Promise<sequence<IDBDatabaseInfo>> databases(); shortcmp(anyfirst, anysecond); }; dictionaryIDBDatabaseInfo { DOMStringname; unsignedlonglongversion; }; request = indexedDB . open(name) Attempts to open a connection to the named database with the current version, or 1 if it does not already exist. If the request is successful request’s result will be the connection.

request = indexedDB . open(name, version) Attempts to open a connection to the named database with the specified version. If the database already exists with a lower version and there are open connections that don’t close in response to a versionchange event, the request will be blocked until they all close, then an upgrade will occur. If the database already exists with a higher version the request will fail. If the request is successful request’s result will be the connection.

request = indexedDB . deleteDatabase(name) Attempts to delete the named database. If the database already exists and there are open connections that don’t close in response to a versionchange event, the request will be blocked until they all close. If the request is successful request’s result will be null.

result = await indexedDB . databases() Returns a promise which resolves to a list of objects giving a snapshot of the names and versions of databases within the storage key.

This API is intended for web applications to introspect the use of databases, for example to clean up from earlier versions of a site’s code. Note that the result is a snapshot; there are no guarantees about the sequencing of the collection of the data or the delivery of the response with respect to requests to create, upgrade, or delete databases by this context or others.

The open(name, version) method steps are:

  1. If version is 0 (zero), throw a TypeError.
  2. Let environment be this’s relevant settings object.
  3. Let storageKey be the result of running obtain a storage key given environment. If failure is returned, then throw a “SecurityError” DOMException and abort these steps.
  4. Let request be a new open request.
  5. Run these steps in parallel:
  6. Let result be the result of opening a database connection, with storageKey, name, version if given and undefined otherwise, and request.

What happens if version is not given? If version is not given and a database with that name already exists, a connection will be opened without changing the version. If version is not given and no database with that name exists, a new database will be created with version equal to 1. 2081. Queue a task to run these steps: 2082. If result is an error, then: 2083. Set request’s result to undefined. 2084. Set request’s error to result. 2085. Set request’s done flag to true. 2086. Fire an event named error at request with its bubbles and cancelable attributes initialized to true. 2087. Otherwise: 2088. Set request’s result to result. 2089. Set request’s done flag to true. 2090. Fire an event named success at request. NOTE: If the steps above resulted in an upgrade transaction being run, these steps will run after that transaction finishes. This ensures that in the case where another version upgrade is about to happen, the success event is fired on the connection first so that the script gets a chance to register a listener for the versionchange event.

Why aren’t the steps to fire a success event or fire an error event used? There is no transaction associated with the request (at this point), so those steps — which activate an associated transaction before dispatch and deactivate the transaction after dispatch — do not apply. 2094. Return a new IDBOpenDBRequest object for request. The deleteDatabase(name) method steps are:

  1. Let environment be this’s relevant settings object.
  2. Let storageKey be the result of running obtain a storage key given environment. If failure is returned, then throw a “SecurityError” DOMException and abort these steps.
  3. Let request be a new open request.
  4. Run these steps in parallel:
  5. Let result be the result of deleting a database, with storageKey, name, and request.
  6. Set request’s processed flag to true.
  7. Queue a task to run these steps:
  8. If result is an error, set request’s error to result, set request’s done flag to true, and fire an event named error at request with its bubbles and cancelable attributes initialized to true.
  9. Otherwise, set request’s result to undefined, set request’s done flag to true, and fire a version change event named success at request with result and null.

Why aren’t the steps to fire a success event or fire an error event used? There is no transaction associated with the request, so those steps — which activate an associated transaction before dispatch and deactivate the transaction after dispatch — do not apply. Also, the success event here is a IDBVersionChangeEvent which includes the oldVersion and newVersion details. 2105. Return a new IDBOpenDBRequest object for request. The databases() method steps are:

  1. Let environment be this’s relevant settings object.
  2. Let storageKey be the result of running obtain a storage key given environment. If failure is returned, then return a promise rejected with a “SecurityError” DOMException
  3. Let p be a new promise.
  4. Run these steps in parallel:
  5. Let databases be the set of databases in storageKey. If this cannot be determined for any reason, then rejectp with an appropriate error (e.g. an “UnknownError” DOMException) and terminate these steps.
  6. Let result be a new list.
  7. For eachdb of databases:
  8. Let info be a new IDBDatabaseInfo dictionary.
  9. Set info’s name dictionary member to db’s name.
  10. Set info’s version dictionary member to db’s version.
  11. Appendinfo to result.
  12. Resolvep with result.
  13. Return p.

🚧 The databases() method is new in this edition. It is supported in Chrome 71, Edge 79, Firefox 126, and Safari 14. 🚧 result = indexedDB . cmp(key1, key2) Compares two values as keys. Returns -1 if key1 precedes key2, 1 if key2 precedes key1, and 0 if the keys are equal.

Throws a “DataError” DOMException if either input is not a valid key.

The cmp(first, second) method steps are:

  1. Let a be the result of converting a value to a key with first. Rethrow any exceptions.
  2. If a is invalid, throw a “DataError” DOMException.
  3. Let b be the result of converting a value to a key with second. Rethrow any exceptions.
  4. If b is invalid, throw a “DataError” DOMException.
  5. Return the results of comparing two keys with a and b.

4.4. The IDBDatabase interface

The IDBDatabase interface represents a connection to a database.

An IDBDatabase object must not be garbage collected if its associated connection’s close pending flag is false and it has one or more event listeners registers whose type is one of abort, error, or versionchange. If an IDBDatabase object is garbage collected, the associated connection must be closed.

Exposed=(Window,Worker) interfaceIDBDatabase : EventTarget { readonlyattributeDOMStringname; readonlyattributeunsignedlonglongversion; readonlyattributeDOMStringListobjectStoreNames; NewObject IDBTransactiontransaction((DOMStringorsequence<DOMString>) storeNames, optionalIDBTransactionModemode = “readonly”, optionalIDBTransactionOptionsoptions = {}); undefinedclose(); NewObject IDBObjectStorecreateObjectStore( DOMStringname, optionalIDBObjectStoreParametersoptions = {}); undefineddeleteObjectStore(DOMStringname); // Event handlers: attributeEventHandleronabort; attributeEventHandleronclose; attributeEventHandleronerror; attributeEventHandleronversionchange; }; enumIDBTransactionDurability { “default”, “strict”, “relaxed” }; dictionaryIDBTransactionOptions { IDBTransactionDurabilitydurability = “default”; }; dictionaryIDBObjectStoreParameters { (DOMStringorsequence<DOMString>)? keyPath = null; booleanautoIncrement = false; }; connection . nameReturns the name of the database.

connection . versionReturns the version of the database.

The name getter steps are to return this’s associated database’s name.

NOTE: The name attribute returns this name even if this’s close pending flag is true. In other words, the value of this attribute stays constant for the lifetime of the IDBDatabase instance.

The version getter steps are to return this’s version.

Is this the same as the database’s version? As long as the connection is open, this is the same as the connected database’s version. But once the connection has closed, this attribute will not reflect changes made with a later upgrade transaction. connection . objectStoreNamesReturns a list of the names of object stores in the database.

store = connection . createObjectStore(name , options) Creates a new object store with the given name and options and returns a new IDBObjectStore.

Throws a “InvalidStateError” DOMException if not called within an upgrade transaction.

connection . deleteObjectStore(name) Deletes the object store with the given name.

Throws a “InvalidStateError” DOMException if not called within an upgrade transaction.

The objectStoreNames getter steps are: 2149. Let names be a list of the names of the object stores in this’s object store set. 2150. Return the result (a DOMStringList) of creating a sorted name list with names.

Is this the same as the database’s object storenames? As long as the connection is open, this is the same as the connected database’s object storenames. But once the connection has closed, this attribute will not reflect changes made with a later upgrade transaction. The createObjectStore(name, options) method steps are:

  1. Let database be this’s associated database.
  2. Let transaction be database’s upgrade transaction if it is not null, or throw an “InvalidStateError” DOMException otherwise.
  3. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  4. Let keyPath be options’s keyPath member if it is not undefined or null, or null otherwise.
  5. If keyPath is not null and is not a valid key path, throw a “SyntaxError” DOMException.
  6. If an object storenamedname already exists in databasethrow a “ConstraintError” DOMException.
  7. Let autoIncrement be options’s autoIncrement member.
  8. If autoIncrement is true and keyPath is an empty string or any sequence (empty or otherwise), throw an “InvalidAccessError” DOMException.
  9. Let store be a new object store in database. Set the created object store’s name to name. If autoIncrement is true, then the created object store uses a key generator. If keyPath is not null, set the created object store’s key path to keyPath.
  10. Return a new object store handle associated with store and transaction. This method creates and returns a new object store with the given name in the connecteddatabase. Note that this method must only be called from within an upgrade transaction.

This method synchronously modifies the objectStoreNames property on the IDBDatabase instance on which it was called.

In some implementations it is possible for the implementation to run into problems after queuing a task to create the object store after the createObjectStore() method has returned. For example in implementations where metadata about the newly created object store is inserted into the database asynchronously, or where the implementation might need to ask the user for permission for quota reasons. Such implementations must still create and return an IDBObjectStore object, and once the implementation determines that creating the object store has failed, it must abort the transaction using the steps to abort a transaction using the appropriate error. For example if creating the object store failed due to quota reasons, a “QuotaExceededError” DOMException must be used as error.

The deleteObjectStore(name) method steps are:

  1. Let database be this’s associated database.
  2. Let transaction be database’s upgrade transaction if it is not null, or throw an “InvalidStateError” DOMException otherwise.
  3. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  4. Let store be the object storenamedname in database, or throw a “NotFoundError” DOMException if none.
  5. Remove store from this’s object store set.
  6. If there is an object store handle associated with store and transaction, remove all entries from its index set.
  7. Destroy store. This method destroys the object store with the given name in the connecteddatabase. Note that this method must only be called from within an upgrade transaction.

This method synchronously modifies the objectStoreNames property on the IDBDatabase instance on which it was called.

transaction = connection . transaction(scope , mode , options ) Returns a new transaction with the given scope (which can be a single object storename or an array of names), mode (“readonly” or “readwrite”), and additional options including durability (“default”, “strict” or “relaxed”).

The default mode is “readonly” and the default durability is “default”.

connection . close() Closes the connection once all running transactions have finished.

The transaction(storeNames, mode, options) method steps are:

  1. If a liveupgrade transaction is associated with the connection, throw an “InvalidStateError” DOMException.
  2. If this’s close pending flag is true, then throw an “InvalidStateError” DOMException.
  3. Let scope be the set of unique strings in storeNames if it is a sequence, or a set containing one string equal to storeNames otherwise.
  4. If any string in scope is not the name of an object store in the connecteddatabase, throw a “NotFoundError” DOMException.
  5. If scope is empty, throw an “InvalidAccessError” DOMException.
  6. If mode is not “readonly” or “readwrite”, throw a TypeError.
  7. Let transaction be a newly createdtransaction with this connection, mode, options’ durability member, and the set of object stores named in scope.
  8. Set transaction’s cleanup event loop to the current event loop.
  9. Return an IDBTransaction object representing transaction.

🚧 The durability option is new in this edition. It is supported in Chrome 82, Edge 82, Firefox 126, and Safari 15. 🚧 NOTE: The created transaction will follow the lifetime rules.

The close() method steps are:

  1. Run close a database connection with this connection. NOTE: The connection will not actually close until all outstanding transactions have completed. Subsequent calls to close() will have no effect.

The onabort attribute is an event handler IDL attribute whose event handler event type is abort.

The onclose attribute is an event handler IDL attribute whose event handler event type is close.

The onerror attribute is an event handler IDL attribute whose event handler event type is error.

The onversionchange attribute is an event handler IDL attribute whose event handler event type is versionchange.

4.5. The IDBObjectStore interface

The IDBObjectStore interface represents an object store handle.

Exposed=(Window,Worker) interfaceIDBObjectStore { attributeDOMStringname; readonlyattributeanykeyPath; readonlyattributeDOMStringListindexNames; SameObject readonlyattributeIDBTransactiontransaction; readonlyattributebooleanautoIncrement; NewObject IDBRequestput(anyvalue, optionalanykey); NewObject IDBRequestadd(anyvalue, optionalanykey); NewObject IDBRequestdelete(anyquery); NewObject IDBRequestclear(); NewObject IDBRequestget(anyquery); NewObject IDBRequestgetKey(anyquery); NewObject IDBRequestgetAll(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestgetAllKeys(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestcount(optionalanyquery); NewObject IDBRequestopenCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); NewObject IDBRequestopenKeyCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); IDBIndexindex(DOMStringname); NewObject IDBIndexcreateIndex(DOMStringname, (DOMStringorsequence<DOMString>) keyPath, optionalIDBIndexParametersoptions = {}); undefineddeleteIndex(DOMStringname); }; dictionaryIDBIndexParameters { booleanunique = false; booleanmultiEntry = false; }; store . nameReturns the name of the store.

store . name = newNameUpdates the name of the store to newName.

Throws “InvalidStateError” DOMException if not called within an upgrade transaction.

store . keyPathReturns the key path of the store, or null if none.

store . indexNamesReturns a list of the names of indexes in the store.

store . transactionReturns the associated transaction.

store . autoIncrementReturns true if the store has a key generator, and false otherwise.

The name getter steps are to return this’s name.

Is this the same as the object store’s name? As long as the transaction has not finished, this is the same as the associated object store’s name. But once the transaction has finished, this attribute will not reflect changes made with a later upgrade transaction. The name setter steps are:

  1. Let name be the given value.
  2. Let transaction be this’s transaction.
  3. Let store be this’s object store.
  4. If store has been deleted, throw an “InvalidStateError” DOMException.
  5. If transaction is not an upgrade transaction, throw an “InvalidStateError” DOMException.
  6. If transaction’s state is not active, throw a “TransactionInactiveError” DOMException.
  7. If store’s name is equal to name, terminate these steps.
  8. If an object storenamedname already exists in store’s database, throw a “ConstraintError” DOMException.
  9. Set store’s name to name.
  10. Set this’s name to name. The keyPath getter steps are to return this’s object store’s key path, or null if none. The key path is converted as a DOMString (if a string) or a sequence<DOMString> (if a list of strings), per WEBIDL.

NOTE: The returned value is not the same instance that was used when the object store was created. However, if this attribute returns an object (specifically an Array), it returns the same object instance every time it is inspected. Changing the properties of the object has no effect on the object store.

The indexNames getter steps are: 2233. Let names be a list of the names of the indexes in this’s index set. 2234. Return the result (a DOMStringList) of creating a sorted name list with names.

Is this the same as object store’s list of indexnames? As long as the transaction has not finished, this is the same as the associated object store’s list of indexnames. But once the transaction has finished, this attribute will not reflect changes made with a later upgrade transaction. The transaction getter steps are to return this’s transaction.

The autoIncrement getter steps are to return true if this’s object store has a key generator, and false otherwise.

The following methods throw a “ReadOnlyError” DOMException if called within a read-only transaction, and a “TransactionInactiveError” DOMException if called when the transaction is not active. request = store . put(value , key) request = store . add(value , key) Adds or updates a record in store with the given value and key.

If the store uses in-line keys and key is specified a “DataError” DOMException will be thrown.

If put() is used, any existing record with the key will be replaced. If add() is used, and if a record with the key already exists the request will fail, with request’s error set to a “ConstraintError” DOMException.

If successful, request’s result will be the record’s key.

request = store . delete(query) Deletes records in store with the given key or in the given key range in query.

If successful, request’s result will be undefined.

request = store . clear() Deletes all records in store.

If successful, request’s result will be undefined.

The put(value, key) method steps are to return the result of running add or put with this, value, key and the no-overwrite flag false.

The add(value, key) method steps are to return the result of running add or put with this, value, key and the no-overwrite flag true.

To add or put with handle, value, key, and no-overwrite flag, run these steps:

  1. Let transaction be handle’s transaction.
  2. Let store be handle’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  6. If store uses in-line keys and key was given, throw a “DataError” DOMException.
  7. If store uses out-of-line keys and has no key generator and key was not given, throw a “DataError” DOMException.
  8. If key was given, then:
  9. Let r be the result of converting a value to a key with key. Rethrow any exceptions.
  10. If r is invalid, throw a “DataError” DOMException.
  11. Let key be r.
  12. Let targetRealm be a user-agent defined Realm.
  13. Let clone be a clone of value in targetRealm during transaction. Rethrow any exceptions.

Why create a copy of the value? The value is serialized when stored. Treating it as a copy here allows other algorithms in this specification to treat it as an ECMAScript value, but implementations can optimize this if the difference in behavior is not observable. 2266. If store uses in-line keys, then: 2267. Let kpk be the result of extracting a key from a value using a key path with clone and store’s key path. Rethrow any exceptions. 2268. If kpk is invalid, throw a “DataError” DOMException. 2269. If kpk is not failure, let key be kpk. 2270. Otherwise (kpk is failure): 2271. If store does not have a key generator, throw a “DataError” DOMException. 2272. Otherwise, if check that a key could be injected into a value with clone and store’s key path return false, throw a “DataError” DOMException. 2273. Let operation be an algorithm to run store a record into an object store with store, clone, key, and no-overwrite flag. 2274. Return the result (an IDBRequest) of running asynchronously execute a request with handle and operation. The delete(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  6. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  7. Let operation be an algorithm to run delete records from an object store with store and range.
  8. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the records to be deleted.

NOTE: Unlike other methods which take keys or key ranges, this method does not allow null to be given as key. This is to reduce the risk that a small bug would clear a whole object store.

The clear() method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  6. Let operation be an algorithm to run clear an object store with store.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation.

The following methods throw a “TransactionInactiveError” DOMException if called when the transaction is not active. request = store . get(query) Retrieves the value of the first record matching the given key or key range in query.

If successful, request’s result will be the value, or undefined if there was no matching record.

request = store . getKey(query) Retrieves the key of the first record matching the given key or key range in query.

If successful, request’s result will be the key, or undefined if there was no matching record.

request = store . getAll(query , count) Retrieves the values of the records matching the given key or key range in query (up to count if given).

If successful, request’s result will be an Array of the values.

request = store . getAllKeys(query , count) Retrieves the keys of records matching the given key or key range in query (up to count if given).

If successful, request’s result will be an Array of the keys.

request = store . count(query) Retrieves the number of records matching the given key or key range in query.

If successful, request’s result will be the count.

The get(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve a value from an object store with the current Realm record, store, and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record value to be retrieved. If a range is specified, the method retrieves the first existing value in that range.

NOTE: This method produces the same result if a record with the given key doesn’t exist as when a record exists, but has undefined as value. If you need to tell the two situations apart, you can use openCursor() with the same key. This will return a cursor with undefined as value if a record exists, or no cursor if no such record exists.

The getKey(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve a key from an object store with store and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record key to be retrieved. If a range is specified, the method retrieves the first existing key in that range.

The getAll(query, count) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve multiple values from an object store with the current Realm record, store, range, and count if given.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record values to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count records in range, only the first count will be retrieved.

The getAllKeys(query, count) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve multiple keys from an object store with store, range, and count if given.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record keys to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count keys in range, only the first count will be retrieved.

The count(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run count the records in a range with store and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the records to be counted. If null or not given, an unbounded key range is used.

The following methods throw a “TransactionInactiveError” DOMException if called when the transaction is not active. request = store . openCursor(query , direction = “next”) Opens a cursor over the records matching query, ordered by direction. If query is null, all records in store are matched.

If successful, request’s result will be an IDBCursorWithValue pointing at the first matching record, or null if there were no matching records.

request = store . openKeyCursor(query , direction = “next”) Opens a cursor with key only flag set to true over the records matching query, ordered by direction. If query is null, all records in store are matched.

If successful, request’s result will be an IDBCursor pointing at the first matching record, or null if there were no matching records.

The openCursor(query, direction) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let cursor be a new cursor with its transaction set to transaction, undefined position, direction set to direction, got value flag set to false, undefined key and value, source set to store, range set to range, and key only flag set to false.
  7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
  8. Let request be the result of running asynchronously execute a request with this and operation.
  9. Set cursor’s request to request.
  10. Return request. NOTE: The query parameter can be a key or key range (an IDBKeyRange) to use as the cursor’s range. If null or not given, an unbounded key range is used.

The openKeyCursor(query, direction) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let cursor be a new cursor with its transaction set to transaction, undefined position, direction set to direction, got value flag set to false, undefined key and value, source set to store, range set to range, and key only flag set to true.
  7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
  8. Let request be the result of running asynchronously execute a request with this and operation.
  9. Set cursor’s request to request.
  10. Return request. NOTE: The query parameter can be a key or key range (an IDBKeyRange) to use as the cursor’s range. If null or not given, an unbounded key range is used.

index = store . index(name) Returns an IDBIndex for the index named name in store.

index = store . createIndex(name, keyPath , options) Creates a new index in store with the given name, keyPath and options and returns a new IDBIndex. If the keyPath and options define constraints that cannot be satisfied with the data already in store the upgrade transaction will abort with a “ConstraintError” DOMException.

Throws an “InvalidStateError” DOMException if not called within an upgrade transaction.

store . deleteIndex(name) Deletes the index in store with the given name.

Throws an “InvalidStateError” DOMException if not called within an upgrade transaction.

The createIndex(name, keyPath, options) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If transaction is not an upgrade transaction, throw an “InvalidStateError” DOMException.
  4. If store has been deleted, throw an “InvalidStateError” DOMException.
  5. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  6. If an indexnamedname already exists in store, throw a “ConstraintError” DOMException.
  7. If keyPath is not a valid key path, throw a “SyntaxError” DOMException.
  8. Let unique be options’s unique member.
  9. Let multiEntry be options’s multiEntry member.
  10. If keyPath is a sequence and multiEntry is true, throw an “InvalidAccessError” DOMException.
  11. Let index be a new index in store. Set index’s name to name, key path to keyPath, unique flag to unique, and multiEntry flag to multiEntry.
  12. Add index to this’s index set.
  13. Return a new index handle associated with index and this. This method creates and returns a new index with the given name in the object store. Note that this method must only be called from within an upgrade transaction.

The index that is requested to be created can contain constraints on the data allowed in the index’s referenced object store, such as requiring uniqueness of the values referenced by the index’s key path. If the referenced object store already contains data which violates these constraints, this must not cause the implementation of createIndex() to throw an exception or affect what it returns. The implementation must still create and return an IDBIndex object, and the implementation must queue a task to abort the upgrade transaction which was used for the createIndex() call.

This method synchronously modifies the indexNames property on the IDBObjectStore instance on which it was called. Although this method does not return an IDBRequest object, the index creation itself is processed as an asynchronous request within the upgrade transaction.

In some implementations it is possible for the implementation to asynchronously run into problems creating the index after the createIndex method has returned. For example in implementations where metadata about the newly created index is queued up to be inserted into the database asynchronously, or where the implementation might need to ask the user for permission for quota reasons. Such implementations must still create and return an IDBIndex object, and once the implementation determines that creating the index has failed, it must run the steps to abort a transaction using an appropriate error. For example if creating the index failed due to quota reasons, a “QuotaExceededError” DOMException must be used as error and if the index can’t be created due to unique flag constraints, a “ConstraintError” DOMException must be used as error.

The asynchronous creation of indexes is observable in the following example:

const request1 = objectStore.put({name:“betty”},1);const request2 = objectStore.put({name:“betty”},2);const index = objectStore.createIndex(“by_name”,“name”,{unique:true});At the point where createIndex() called, neither of the requests have executed. When the second request executes, a duplicate name is created. Since the index creation is considered an asynchronous request, the index’s uniqueness constraint does not cause the second request to fail. Instead, the transaction will be aborted when the index is created and the constraint fails.

The index(name) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is finished, then throw an “InvalidStateError” DOMException.
  5. Let index be the indexnamedname in this’s index set if one exists, or throw a “NotFoundError” DOMException otherwise.
  6. Return an index handle associated with index and this. NOTE: Each call to this method on the same IDBObjectStore instance with the same name returns the same IDBIndex instance.

NOTE: The returned IDBIndex instance is specific to this IDBObjectStore instance. If this method is called on a different IDBObjectStore instance with the same name, a different IDBIndex instance is returned.

The deleteIndex(name) method steps are:

  1. Let transaction be this’s transaction.
  2. Let store be this’s object store.
  3. If transaction is not an upgrade transaction, throw an “InvalidStateError” DOMException.
  4. If store has been deleted, throw an “InvalidStateError” DOMException.
  5. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  6. Let index be the indexnamedname in store if one exists, or throw a “NotFoundError” DOMException otherwise.
  7. Remove index from this’s index set.
  8. Destroy index. This method destroys the index with the given name in the object store. Note that this method must only be called from within an upgrade transaction.

This method synchronously modifies the indexNames property on the IDBObjectStore instance on which it was called. Although this method does not return an IDBRequest object, the index destruction itself is processed as an asynchronous request within the upgrade transaction.

4.6. The IDBIndex interface

The IDBIndex interface represents an index handle.

Exposed=(Window,Worker) interfaceIDBIndex { attributeDOMStringname; SameObject readonlyattributeIDBObjectStoreobjectStore; readonlyattributeanykeyPath; readonlyattributebooleanmultiEntry; readonlyattributebooleanunique; NewObject IDBRequestget(anyquery); NewObject IDBRequestgetKey(anyquery); NewObject IDBRequestgetAll(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestgetAllKeys(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestcount(optionalanyquery); NewObject IDBRequestopenCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); NewObject IDBRequestopenKeyCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); }; index . nameReturns the name of the index.

index . name = newNameUpdates the name of the store to newName.

Throws an “InvalidStateError” DOMException if not called within an upgrade transaction.

index . objectStoreReturns the IDBObjectStore the index belongs to.

index . keyPath Returns the key path of the index.

index . multiEntry Returns true if the index’s multiEntry flag is true.

index . unique Returns true if the index’s unique flag is true.

The name getter steps are to return this’s name.

Is this the same as the index’s name? As long as the transaction has not finished, this is the same as the associated index’s name. But once the transaction has finished, this attribute will not reflect changes made with a later upgrade transaction. The name setter steps are:

  1. Let name be the given value.
  2. Let transaction be this’s transaction.
  3. Let index be this’s index.
  4. If transaction is not an upgrade transaction, throw an “InvalidStateError” DOMException.
  5. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  6. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  7. If index’s name is equal to name, terminate these steps.
  8. If an indexnamedname already exists in index’s object store, throw a “ConstraintError” DOMException.
  9. Set index’s name to name.
  10. Set this’s name to name. The objectStore getter steps are to return this’s object store handle.

The keyPath getter steps are to return this’s index’s key path. The key path is converted as a DOMString (if a string) or a sequence<DOMString> (if a list of strings), per WEBIDL.

NOTE: The returned value is not the same instance that was used when the index was created. However, if this attribute returns an object (specifically an Array), it returns the same object instance every time it is inspected. Changing the properties of the object has no effect on the index.

The multiEntry getter steps are to return this’s index’s multiEntry flag.

The unique getter steps are to return this’s index’s unique flag.

The following methods throw an “TransactionInactiveError” DOMException if called when the transaction is not active. request = index . get(query) Retrieves the value of the first record matching the given key or key range in query.

If successful, request’s result will be the value, or undefined if there was no matching record.

request = index . getKey(query) Retrieves the key of the first record matching the given key or key range in query.

If successful, request’s result will be the key, or undefined if there was no matching record.

request = index . getAll(query , count) Retrieves the values of the records matching the given key or key range in query (up to count if given).

If successful, request’s result will be an Array of the values.

request = index . getAllKeys(query , count) Retrieves the keys of records matching the given key or key range in query (up to count if given).

If successful, request’s result will be an Array of the keys.

request = index . count(query) Retrieves the number of records matching the given key or key range in query.

If successful, request’s result will be the count.

The get(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve a referenced value from an index with the current Realm record, index, and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the referenced value to be retrieved. If a range is specified, the method retrieves the first existing record in that range.

NOTE: This method produces the same result if a record with the given key doesn’t exist as when a record exists, but has undefined as value. If you need to tell the two situations apart, you can use openCursor() with the same key. This will return a cursor with undefined as value if a record exists, or no cursor if no such record exists.

The getKey(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query and true. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve a value from an index with index and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record key to be retrieved. If a range is specified, the method retrieves the first existing key in that range.

The getAll(query, count) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve multiple referenced values from an index with the current Realm record, index, range, and count if given.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the referenced values to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count records in range, only the first count will be retrieved.

The getAllKeys(query, count) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run retrieve multiple values from an index with index, range, and count if given.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the record keys to be retrieved. If null or not given, an unbounded key range is used. If count is specified and there are more than count keys in range, only the first count will be retrieved.

The count(query) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let operation be an algorithm to run count the records in a range with index and range.
  7. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: The query parameter can be a key or key range (an IDBKeyRange) identifying the records to be counted. If null or not given, an unbounded key range is used.

The following methods throw an “TransactionInactiveError” DOMException if called when the transaction is not active. request = index . openCursor(query , direction = “next”) Opens a cursor over the records matching query, ordered by direction. If query is null, all records in index are matched.

If successful, request’s result will be an IDBCursorWithValue, or null if there were no matching records.

request = index . openKeyCursor(query , direction = “next”) Opens a cursor with key only flag set to true over the records matching query, ordered by direction. If query is null, all records in index are matched.

If successful, request’s result will be an IDBCursor, or null if there were no matching records.

The openCursor(query, direction) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let cursor be a new cursor with its transaction set to transaction, undefined position, direction set to direction, got value flag set to false, undefined key and value, source set to index, range set to range, and key only flag set to false.
  7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
  8. Let request be the result of running asynchronously execute a request with this and operation.
  9. Set cursor’s request to request.
  10. Return request. NOTE: The query parameter can be a key or key range (an IDBKeyRange) to use as the cursor’s range. If null or not given, an unbounded key range is used.

The openKeyCursor(query, direction) method steps are:

  1. Let transaction be this’s transaction.
  2. Let index be this’s index.
  3. If index or index’s object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  5. Let range be the result of converting a value to a key range with query. Rethrow any exceptions.
  6. Let cursor be a new cursor with its transaction set to transaction, undefined position, direction set to direction, got value flag set to false, undefined key and value, source set to index, range set to range, and key only flag set to true.
  7. Let operation be an algorithm to run iterate a cursor with the current Realm record and cursor.
  8. Let request be the result of running asynchronously execute a request with this and operation.
  9. Set cursor’s request to request.
  10. Return request. NOTE: The query parameter can be a key or key range (an IDBKeyRange) to use as the cursor’s range. If null or not given, an unbounded key range is used.

4.7. The IDBKeyRange interface

The IDBKeyRange interface represents a key range.

Exposed=(Window,Worker) interfaceIDBKeyRange { readonlyattributeanylower; readonlyattributeanyupper; readonlyattributebooleanlowerOpen; readonlyattributebooleanupperOpen; // Static construction methods: NewObject staticIDBKeyRangeonly(anyvalue); NewObject staticIDBKeyRangelowerBound(anylower, optionalbooleanopen = false); NewObject staticIDBKeyRangeupperBound(anyupper, optionalbooleanopen = false); NewObject staticIDBKeyRangebound(anylower, anyupper, optionalbooleanlowerOpen = false, optionalbooleanupperOpen = false); booleanincludes(anykey); }; range . lowerReturns the range’s lower bound, or undefined if none.

range . upperReturns the range’s upper bound, or undefined if none.

range . lowerOpenReturns the range’s lower open flag.

range . upperOpenReturns the range’s upper open flag.

The lower getter steps are to return the result of converting a key to a value with this’s lower bound if it is not null, or undefined otherwise.

The upper getter steps are to return the result of converting a key to a value with this’s upper bound if it is not null, or undefined otherwise.

The lowerOpen getter steps are to return this’s lower open flag.

The upperOpen getter steps are to return this’s upper open flag.

range = IDBKeyRange . only(key) Returns a new IDBKeyRange spanning only key.

range = IDBKeyRange . lowerBound(key , open = false) Returns a new IDBKeyRange starting at key with no upper bound. If open is true, key is not included in the range.

range = IDBKeyRange . upperBound(key , open = false) Returns a new IDBKeyRange with no lower bound and ending at key. If open is true, key is not included in the range.

range = IDBKeyRange . bound(lower, upper , lowerOpen = false , upperOpen = false) Returns a new IDBKeyRange spanning from lower to upper. If lowerOpen is true, lower is not included in the range. If upperOpen is true, upper is not included in the range.

The only(value) method steps are:

  1. Let key be the result of converting a value to a key with value. Rethrow any exceptions.

  2. If key is invalid, throw a “DataError” DOMException.

  3. Create and return a new key rangecontaining onlykey. The lowerBound(lower, open) method steps are:

  4. Let lowerKey be the result of converting a value to a key with lower. Rethrow any exceptions.

  5. If lowerKey is invalid, throw a “DataError” DOMException.

  6. Create and return a new key range with lower bound set to lowerKey, lower open flag set to open, upper bound set to null, and upper open flag set to true. The upperBound(upper, open) method steps are:

  7. Let upperKey be the result of converting a value to a key with upper. Rethrow any exceptions.

  8. If upperKey is invalid, throw a “DataError” DOMException.

  9. Create and return a new key range with lower bound set to null, lower open flag set to true, upper bound set to upperKey, and upper open flag set to open. The bound(lower, upper, lowerOpen, upperOpen) method steps are:

  10. Let lowerKey be the result of converting a value to a key with lower. Rethrow any exceptions.

  11. If lowerKey is invalid, throw a “DataError” DOMException.

  12. Let upperKey be the result of converting a value to a key with upper. Rethrow any exceptions.

  13. If upperKey is invalid, throw a “DataError” DOMException.

  14. If lowerKey is greater thanupperKey, throw a “DataError” DOMException.

  15. Create and return a new key range with lower bound set to lowerKey, lower open flag set to lowerOpen, upper bound set to upperKey and upper open flag set to upperOpen. range . includes(key) Returns true if key is included in the range, and false otherwise.

The includes(key) method steps are:

  1. Let k be the result of converting a value to a key with key. Rethrow any exceptions.
  2. If k is invalid, throw a “DataError” DOMException.
  3. Return true if k is in this range, and false otherwise.

4.8. The IDBCursor interface

Cursor objects implement the IDBCursor interface. There is only ever one IDBCursor instance representing a given cursor. There is no limit on how many cursors can be used at the same time.

Exposed=(Window,Worker) interfaceIDBCursor { readonlyattribute (IDBObjectStoreorIDBIndex) source; readonlyattributeIDBCursorDirectiondirection; readonlyattributeanykey; readonlyattributeanyprimaryKey; SameObject readonlyattributeIDBRequestrequest; undefinedadvance(EnforceRange unsignedlongcount); undefinedcontinue(optionalanykey); undefinedcontinuePrimaryKey(anykey, anyprimaryKey); NewObject IDBRequestupdate(anyvalue); NewObject IDBRequestdelete(); }; enumIDBCursorDirection { “next”, “nextunique”, “prev”, “prevunique” }; cursor . sourceReturns the IDBObjectStore or IDBIndex the cursor was opened from.

cursor . directionReturns the direction (“next”, “nextunique”, “prev” or “prevunique”) of the cursor.

cursor . keyReturns the key of the cursor. Throws a “InvalidStateError” DOMException if the cursor is advancing or is finished.

cursor . primaryKeyReturns the effective key of the cursor. Throws a “InvalidStateError” DOMException if the cursor is advancing or is finished.

cursor . requestReturns the request that was used to obtain this cursor.

The source getter steps are to return this’s source.

NOTE: The source attribute never returns null or throws an exception, even if the cursor is currently being iterated, has iterated past its end, or its transaction is not active.

The direction getter steps are to return this’s direction.

The key getter steps are to return the result of converting a key to a value with the cursor’s current key.

NOTE: If key returns an object (e.g. a Date or Array), it returns the same object instance every time it is inspected, until the cursor’s key is changed. This means that if the object is modified, those modifications will be seen by anyone inspecting the value of the cursor. However modifying such an object does not modify the contents of the database.

The primaryKey getter steps are to return the result of converting a key to a value with the cursor’s current effective key.

NOTE: If primaryKey returns an object (e.g. a Date or Array), it returns the same object instance every time it is inspected, until the cursor’s effective key is changed. This means that if the object is modified, those modifications will be seen by anyone inspecting the value of the cursor. However modifying such an object does not modify the contents of the database.

The request getter steps are to return this’s request.

🚧 The request attribute is new in this edition. It is supported in Chrome 76, Edge 79, Firefox 77, and Safari 15. 🚧 The following methods advance a cursor. Once the cursor has advanced, a success event will be fired at the same IDBRequest returned when the cursor was opened. The result will be the same cursor if a record was in range, or undefined otherwise. If called while the cursor is already advancing, an “InvalidStateError” DOMException will be thrown.

The following methods throw a “TransactionInactiveError” DOMException if called when the transaction is not active.

cursor . advance(count) Advances the cursor through the next countrecords in range.

cursor . continue() Advances the cursor to the next record in range.

cursor . continue(key) Advances the cursor to the next record in range matching or after key.

cursor . continuePrimaryKey(key, primaryKey) Advances the cursor to the next record in range matching or after key and primaryKey. Throws an “InvalidAccessError” DOMException if the source is not an index.

The advance(count) method steps are:

  1. If count is 0 (zero), throw a TypeError.
  2. Let transaction be this’s transaction.
  3. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  4. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  5. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  6. Set this’s got value flag to false.
  7. Let request be this’s request.
  8. Set request’s processed flag to false.
  9. Set request’s done flag to false.
  10. Let operation be an algorithm to run iterate a cursor with the current Realm record, this, and count.
  11. Run asynchronously execute a request with this’s source, operation, and request. NOTE: Calling this method more than once before new cursor data has been loaded - for example, calling advance() twice from the same onsuccess handler - results in an “InvalidStateError” DOMException being thrown on the second call because the cursor’s got value flag has been set to false.

The continue(key) method steps are:

  1. Let transaction be this’s transaction.
  2. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  3. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  5. If key is given, then:
  6. Let r be the result of converting a value to a key with key. Rethrow any exceptions.
  7. If r is invalid, throw a “DataError” DOMException.
  8. Let key be r.
  9. If key is less than or equal tothis’s position and this’s direction is “next” or “nextunique”, then throw a “DataError” DOMException.
  10. If key is greater than or equal tothis’s position and this’s direction is “prev” or “prevunique”, then throw a “DataError” DOMException.
  11. Set this’s got value flag to false.
  12. Let request be this’s request.
  13. Set request’s processed flag to false.
  14. Set request’s done flag to false.
  15. Let operation be an algorithm to run iterate a cursor with the current Realm record, this, and key (if given).
  16. Run asynchronously execute a request with this’s source, operation, and request. NOTE: Calling this method more than once before new cursor data has been loaded - for example, calling continue() twice from the same onsuccess handler - results in an “InvalidStateError” DOMException being thrown on the second call because the cursor’s got value flag has been set to false.

The continuePrimaryKey(key, primaryKey) method steps are:

  1. Let transaction be this’s transaction.
  2. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  3. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  4. If this’s source is not an indexthrow an “InvalidAccessError” DOMException.
  5. If this’s direction is not “next” or “prev”, throw an “InvalidAccessError” DOMException.
  6. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  7. Let r be the result of converting a value to a key with key. Rethrow any exceptions.
  8. If r is invalid, throw a “DataError” DOMException.
  9. Let key be r.
  10. Let r be the result of converting a value to a key with primaryKey. Rethrow any exceptions.
  11. If r is invalid, throw a “DataError” DOMException.
  12. Let primaryKey be r.
  13. If key is less thanthis’s position and this’s direction is “next”, throw a “DataError” DOMException.
  14. If key is greater thanthis’s position and this’s direction is “prev”, throw a “DataError” DOMException.
  15. If key is equal tothis’s position and primaryKey is less than or equal tothis’s object store position and this’s direction is “next”, throw a “DataError” DOMException.
  16. If key is equal tothis’s position and primaryKey is greater than or equal tothis’s object store position and this’s direction is “prev”, throw a “DataError” DOMException.
  17. Set this’s got value flag to false.
  18. Let request be this’s request.
  19. Set request’s processed flag to false.
  20. Set request’s done flag to false.
  21. Let operation be an algorithm to run iterate a cursor with the current Realm record, this, key, and primaryKey.
  22. Run asynchronously execute a request with this’s source, operation, and request. NOTE: Calling this method more than once before new cursor data has been loaded - for example, calling continuePrimaryKey() twice from the same onsuccess handler - results in an “InvalidStateError” DOMException being thrown on the second call because the cursor’s got value flag has been set to false.

The following methods throw a “ReadOnlyError” DOMException if called within a read-only transaction, and a “TransactionInactiveError” DOMException if called when the transaction is not active. request = cursor . update(value) Updated the record pointed at by the cursor with a new value.

Throws a “DataError” DOMException if the effective object store uses in-line keys and the key would have changed.

If successful, request’s result will be the record’s key.

request = cursor . delete() Delete the record pointed at by the cursor with a new value.

If successful, request’s result will be undefined.

The update(value) method steps are:

  1. Let transaction be this’s transaction.
  2. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  3. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  4. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  5. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  6. If this’s key only flag is true, throw an “InvalidStateError” DOMException.
  7. Let targetRealm be a user-agent defined Realm.
  8. Let clone be a clone of value in targetRealm during transaction. Rethrow any exceptions.

Why create a copy of the value? The value is serialized when stored. Treating it as a copy here allows other algorithms in this specification to treat it as an ECMAScript value, but implementations can optimize this if the difference in behavior is not observable. 2708. If this’s effective object store uses in-line keys, then: 2709. Let kpk be the result of extracting a key from a value using a key path with clone and the key path of this’s effective object store. Rethrow any exceptions. 2710. If kpk is failure, invalid, or not equal tothis’s effective key, throw a “DataError” DOMException. 2711. Let operation be an algorithm to run store a record into an object store with this’s effective object store, clone, this’s effective key, and false. 2712. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. NOTE: A result of storing a record into an object store is that if the record has been deleted since the cursor moved to it, a new record will be created.

The delete() method steps are:

  1. Let transaction be this’s transaction.
  2. If transaction’s state is not active, then throw a “TransactionInactiveError” DOMException.
  3. If transaction is a read-only transaction, throw a “ReadOnlyError” DOMException.
  4. If this’s source or effective object store has been deleted, throw an “InvalidStateError” DOMException.
  5. If this’s got value flag is false, indicating that the cursor is being iterated or has iterated past its end, throw an “InvalidStateError” DOMException.
  6. If this’s key only flag is true, throw an “InvalidStateError” DOMException.
  7. Let operation be an algorithm to run delete records from an object store with this’s effective object store and this’s effective key.
  8. Return the result (an IDBRequest) of running asynchronously execute a request with this and operation. A cursor that has its key only flag set to false implements the IDBCursorWithValue interface as well.

Exposed=(Window,Worker) interfaceIDBCursorWithValue : IDBCursor { readonlyattributeanyvalue; }; cursor . valueReturns the cursor’s current value.

The value getter steps are to return this’s current value.

NOTE: If value returns an object, it returns the same object instance every time it is inspected, until the cursor’s value is changed. This means that if the object is modified, those modifications will be seen by anyone inspecting the value of the cursor. However modifying such an object does not modify the contents of the database.

4.9. The IDBTransaction interface

Transaction objects implement the following interface:

Exposed=(Window,Worker) interfaceIDBTransaction : EventTarget { readonlyattributeDOMStringListobjectStoreNames; readonlyattributeIDBTransactionModemode; readonlyattributeIDBTransactionDurabilitydurability; SameObject readonlyattributeIDBDatabasedb; readonlyattributeDOMException? error; IDBObjectStoreobjectStore(DOMStringname); undefinedcommit(); undefinedabort(); // Event handlers: attributeEventHandleronabort; attributeEventHandleroncomplete; attributeEventHandleronerror; }; enumIDBTransactionMode { “readonly”, “readwrite”, “versionchange” }; transaction . objectStoreNamesReturns a list of the names of object stores in the transaction’s scope. For an upgrade transaction this is all object stores in the database.

transaction . modeReturns the mode the transaction was created with (“readonly” or “readwrite”), or “versionchange” for an upgrade transaction.

transaction . durabilityReturns the durability hint the transaction was created with (“strict”, “relaxed”), or “default”).

transaction . dbReturns the transaction’s connection.

transaction . errorIf the transaction was aborted, returns the error (a DOMException) providing the reason.

The objectStoreNames getter steps are:

  1. Let names be a list of the names of the object stores in this’s scope.
  2. Return the result (a DOMStringList) of creating a sorted name list with names. NOTE: The contents of each list returned by this attribute does not change, but subsequent calls to this attribute during an upgrade transaction can return lists with different contents as object stores are created and deleted.

The mode getter steps are to return this’s mode.

The durability getter steps are to return this’s durability hint.

🚧 The durability attribute is new in this edition. It is supported in Chrome 82, Edge 82, Firefox 126, and Safari 15. 🚧 The db getter steps are to return this’s connection’s associated database.

The error getter steps are to return this’s error, or null if none.

NOTE: If this transaction was aborted due to a failed request, this will be the same as the request’s error. If this transaction was aborted due to an uncaught exception in an event handler, the error will be a “AbortError” DOMException. If the transaction was aborted due to an error while committing, it will reflect the reason for the failure (e.g. “QuotaExceededError”, “ConstraintError”, or “UnknownError” DOMException).

transaction . objectStore(name) Returns an IDBObjectStore in the transaction’s scope.

transaction . abort()Aborts the transaction. All pending requests will fail with a “AbortError” DOMException and all changes made to the database will be reverted.

transaction . commit()Attempts to commit the transaction. All pending requests will be allowed to complete, but no new requests will be accepted. This can be used to force a transaction to quickly finish, without waiting for pending requests to fire success events before attempting to commit normally.

The transaction will abort if a pending request fails, for example due to a constraint error. The success events for successful requests will still fire, but throwing an exception in an event handler will not abort the transaction. Similarly, error events for failed requests will still fire, but calling preventDefault() will not prevent the transaction from aborting.

The objectStore(name) method steps are:

  1. If this’s state is finished, then throw an “InvalidStateError” DOMException.
  2. Let store be the object storenamedname in this’s scope, or throw a “NotFoundError” DOMException if none.
  3. Return an object store handle associated with store and this. NOTE: Each call to this method on the same IDBTransaction instance with the same name returns the same IDBObjectStore instance.

NOTE: The returned IDBObjectStore instance is specific to this IDBTransaction. If this method is called on a different IDBTransaction, a different IDBObjectStore instance is returned.

The abort() method steps are:

  1. If this’s state is committing or finished, then throw an “InvalidStateError” DOMException.

  2. Set this’s state to inactive and run abort a transaction with this and null. The commit() method steps are:

  3. If this’s state is not active, then throw an “InvalidStateError” DOMException.

  4. Run commit a transaction with this.

🚧 The commit() method is new in this edition. It is supported in Chrome 76, Edge 79, Firefox 74, and Safari 15. 🚧 NOTE: It is not normally necessary to call commit() on a transaction. A transaction will automatically commit when all outstanding requests have been satisfied and no new requests have been made. This call can be used to start the commit process without waiting for events from outstanding requests to be dispatched.

The onabort attribute is an event handler IDL attribute whose event handler event type is abort.

The oncomplete attribute is an event handler IDL attribute whose event handler event type is complete.

The onerror attribute is an event handler IDL attribute whose event handler event type is error.

NOTE: To determine if a transaction has completed successfully, listen to the transaction’s complete event rather than the success event of a particular request, because the transaction can still fail after the success event fires.

5. Algorithms

5.1. Opening a database connection

To open a database connection with storageKey which requested the database to be opened, a database name, a database version, and a request, run these steps:

  1. Let queue be the connection queue for storageKey and name.
  2. Add request to queue.
  3. Wait until all previous requests in queue have been processed.
  4. Let db be the databasenamedname in storageKey, or null otherwise.
  5. If version is undefined, let version be 1 if db is null, or db’s version otherwise.
  6. If db is null, let db be a new database with namename, version 0 (zero), and with no object stores. If this fails for any reason, return an appropriate error (e.g. a “QuotaExceededError” or “UnknownError” DOMException).
  7. If db’s version is greater than version, return a newly created “VersionError” DOMException and abort these steps.
  8. Let connection be a new connection to db.
  9. Set connection’s version to version.
  10. If db’s version is less than version, then:
  11. Let openConnections be the set of all connections, except connection, associated with db.
  12. For eachentry of openConnections that does not have its close pending flag set to true, queue a task to fire a version change event named versionchange at entry with db’s version and version.

NOTE: Firing this event might cause one or more of the other objects in openConnections to be closed, in which case the versionchange event is not fired at those objects, even if that hasn’t yet been done. 2790. Wait for all of the events to be fired. 2791. If any of the connections in openConnections are still not closed, queue a task to fire a version change event named blocked at request with db’s version and version. 2792. Wait until all connections in openConnections are closed. 2793. Run upgrade a database using connection, version and request. 2794. If connection was closed, return a newly created “AbortError” DOMException and abort these steps. 2795. If the upgrade transaction was aborted, run the steps to close a database connection with connection, return a newly created “AbortError” DOMException and abort these steps. 2796. Return connection.

5.2. Closing a database connection

To close a database connection with a connection object, and an optional forced flag, run these steps:

  1. Set connection’s close pending flag to true.
  2. If the forced flag is true, then for each transactioncreated using connection run abort a transaction with transaction and newly created “AbortError” DOMException.
  3. Wait for all transactions created using connection to complete. Once they are complete, connection is closed.
  4. If the forced flag is true, then fire an event named close at connection.

NOTE: The close event only fires if the connection closes abnormally, e.g. if the storage key’s storage is cleared, or there is corruption or an I/O error. If close() is called explicitly the event does not fire. NOTE: Once a connection’s close pending flag has been set to true, no new transactions can be created using the connection. All methods that create transactions first check the connection’s close pending flag first and throw an exception if it is true.

NOTE: Once the connection is closed, this can unblock the steps to upgrade a database, and the steps to delete a database, which bothwait for connections to a given database to be closed before continuing.

5.3. Deleting a database

To delete a database with the storageKey that requested the database to be deleted, a database name, and a request, run these steps:

  1. Let queue be the connection queue for storageKey and name.
  2. Add request to queue.
  3. Wait until all previous requests in queue have been processed.
  4. Let db be the databasenamedname in storageKey, if one exists. Otherwise, return 0 (zero).
  5. Let openConnections be the set of all connections associated with db.
  6. For eachentry of openConnections that does not have its close pending flag set to true, queue a task to fire a version change event named versionchange at entry with db’s version and null.

NOTE: Firing this event might cause one or more of the other objects in openConnections to be closed, in which case the versionchange event is not fired at those objects, even if that hasn’t yet been done. 2813. Wait for all of the events to be fired. 2814. If any of the connections in openConnections are still not closed, queue a task to fire a version change event named blocked at request with db’s version and null. 2815. Wait until all connections in openConnections are closed. 2816. Let version be db’s version. 2817. Delete db. If this fails for any reason, return an appropriate error (e.g. “QuotaExceededError” or “UnknownError” DOMException). 2818. Return version.

5.4. Committing a transaction

To commit a transaction with the transaction to commit, run these steps:

  1. Set transaction’s state to committing.
  2. Run the following steps in parallel:
  3. Wait until every item in transaction’s request list is processed.
  4. If transaction’s state is no longer committing, then terminate these steps.
  5. Attempt to write any outstanding changes made by transaction to the database, considering transaction’s durability hint.
  6. If an error occurs while writing the changes to the database, then run abort a transaction with transaction and an appropriate type for the error, for example “QuotaExceededError” or “UnknownError” DOMException, and terminate these steps.
  7. Queue a task to run these steps:
  8. If transaction is an upgrade transaction, then set transaction’s connection’s associated database’s upgrade transaction to null.
  9. Set transaction’s state to finished.
  10. Fire an event named complete at transaction.

NOTE: Even if an exception is thrown from one of the event handlers of this event, the transaction is still committed since writing the database changes happens before the event takes place. Only after the transaction has been successfully written is the complete event fired. 2831. If transaction is an upgrade transaction, then let request be the request associated with transaction and set request’s transaction to null.

5.5. Aborting a transaction

To abort a transaction with the transaction to abort, and error, run these steps:

  1. All the changes made to the database by the transaction are reverted. For upgrade transactions this includes changes to the set of object stores and indexes, as well as the change to the version. Any object stores and indexes which were created during the transaction are now considered deleted for the purposes of other algorithms.
  2. If transaction is an upgrade transaction, run the steps to abort an upgrade transaction with transaction.

NOTE: This reverts changes to all connection, object store handle, and index handle instances associated with transaction. 2836. Set transaction’s state to finished. 2837. If error is not null, set transaction’s error to error. 2838. For eachrequest of transaction’s request list, abort the steps to asynchronously execute a request for request, set request’s processed flag to true, and queue a task to run these steps: 2839. Set request’s done flag to true. 2840. Set request’s result to undefined. 2841. Set request’s error to a newly created “AbortError” DOMException. 2842. Fire an event named error at request with its bubbles and cancelable attributes initialized to true. NOTE: This does not always result in any error events being fired. For example if a transaction is aborted due to an error while committing the transaction, or if it was the last remaining request that failed.

  1. Queue a task to run these steps:
  2. If transaction is an upgrade transaction, then set transaction’s connection’s associated database’s upgrade transaction to null.
  3. Fire an event named abort at transaction with its bubbles attribute initialized to true.
  4. If transaction is an upgrade transaction, then:
  5. Let request be the open request associated with transaction.
  6. Set request’s transaction to null.
  7. Set request’s result to undefined.
  8. Set request’s processed flag to false.
  9. Set request’s done flag to false.

5.6. Asynchronously executing a request

To asynchronously execute a request with the source object and an operation to perform on a database, and an optional request, run these steps:

These steps can be aborted at any point if the transaction the created request belongs to is aborted using the steps to abort a transaction.

  1. Let transaction be the transaction associated with source.
  2. Assert: transaction’s state is active.
  3. If request was not given, let request be a new request with source as source.
  4. Add request to the end of transaction’s request list.
  5. Run these steps in parallel:
  6. Wait until request is the first item in transaction’s request list that is not processed.
  7. Let result be the result of performing operation.
  8. If result is an error and transaction’s state is committing, then run abort a transaction with transaction and result, and terminate these steps.
  9. If result is an error, then revert all changes made by operation.

NOTE: This only reverts the changes done by this request, not any other changes made by the transaction. 2865. Set request’s processed flag to true. 2866. Queue a task to run these steps: 2867. Remove request from transaction’s request list. 2868. Set request’s done flag to true. 2869. If result is an error, then: 2870. Set request’s result to undefined. 2871. Set request’s error to result. 2872. Fire an error event at request. 2873. Otherwise: 2874. Set request’s result to result. 2875. Set request’s error to undefined. 2876. Fire a success event at request. 2877. Return request.

5.7. Upgrading a database

To upgrade a database with connection (a connection), a new version, and a request, run these steps:

  1. Let db be connection’s database.
  2. Let transaction be a new upgrade transaction with connection used as connection.
  3. Set transaction’s scope to connection’s object store set.
  4. Set db’s upgrade transaction to transaction.
  5. Set transaction’s state to inactive.
  6. Start transaction.

NOTE: Note that until this transaction is finished, no other connections can be opened to the same database. 2886. Let old version be db’s version. 2887. Set db’s version to version. This change is considered part of the transaction, and so if the transaction is aborted, this change is reverted. 2888. Set request’s processed flag to true. 2889. Queue a task to run these steps: 2890. Set request’s result to connection. 2891. Set request’s transaction to transaction. 2892. Set request’s done flag to true. 2893. Set transaction’s state to active. 2894. Let didThrow be the result of firing a version change event named upgradeneeded at request with old version and version. 2895. Set transaction’s state to inactive. 2896. If didThrow is true, run abort a transaction with transaction and a newly created “AbortError” DOMException. 2897. Wait for transaction to finish.

NOTE: Some of the algorithms invoked during the transaction’s lifetime, such as the steps to commit a transaction and the steps to abort a transaction, include steps specific to upgrade transactions.

5.8. Aborting an upgrade transaction

To abort an upgrade transaction with transaction, run these steps:

NOTE: These steps are run as needed by the steps to abort a transaction, which revert changes to the database including the set of associated object stores and indexes, as well as the change to the version.

  1. Let connection be transaction’s connection.
  2. Let database be connection’s database.
  3. Set connection’s version to database’s version if database previously existed, or 0 (zero) if database was newly created.

NOTE: This reverts the value of version returned by the IDBDatabase object. 2904. Set connection’s object store set to the set of object stores in database if database previously existed, or the empty set if database was newly created.

NOTE: This reverts the value of objectStoreNames returned by the IDBDatabase object. 2905. For each object store handlehandle associated with transaction, including those for object stores that were created or deleted during transaction: 2906. If handle’s object store was not newly created during transaction, set handle’s name to its object store’s name. 2907. Set handle’s index set to the set of indexes that reference its object store. NOTE: This reverts the values of name and indexNames returned by related IDBObjectStore objects.

How is this observable? Although script cannot access an object store by using the objectStore() method on an IDBTransaction instance after the transaction is aborted, it can still have references to IDBObjectStore instances where the name and indexNames properties can be queried. 2911. For each index handlehandle associated with transaction, including those for indexes that were created or deleted during transaction: 2912. If handle’s index was not newly created during transaction, set handle’s name to its index’s name. NOTE: This reverts the value of name returned by related IDBIndex objects.

How is this observable? Although script cannot access an index by using the index() method on an IDBObjectStore instance after the transaction is aborted, it can still have references to IDBIndex instances where the name property can be queried. NOTE: The name property of the IDBDatabase instance is not modified, even if the aborted upgrade transaction was creating a new database.

5.9. Firing a success event

To fire a success event at a request, run these steps:

  1. Let event be the result of creating an event using Event.
  2. Set event’s type attribute to “success”.
  3. Set event’s bubbles and cancelable attributes to false.
  4. Let transaction be request’s transaction.
  5. Let legacyOutputDidListenersThrowFlag be initially false.
  6. If transaction’s state is inactive, then set transaction’s state to active.
  7. Dispatchevent at request with legacyOutputDidListenersThrowFlag.
  8. If transaction’s state is active, then:
  9. Set transaction’s state to inactive.
  10. If legacyOutputDidListenersThrowFlag is true, then run abort a transaction with transaction and a newly created “AbortError” DOMException.
  11. If transaction’s request list is empty, then run commit a transaction with transaction.

5.10. Firing an error event

To fire an error event at a request, run these steps:

  1. Let event be the result of creating an event using Event.
  2. Set event’s type attribute to “error”.
  3. Set event’s bubbles and cancelable attributes to true.
  4. Let transaction be request’s transaction.
  5. Let legacyOutputDidListenersThrowFlag be initially false.
  6. If transaction’s state is inactive, then set transaction’s state to active.
  7. Dispatchevent at request with legacyOutputDidListenersThrowFlag.
  8. If transaction’s state is active, then:
  9. Set transaction’s state to inactive.
  10. If legacyOutputDidListenersThrowFlag is true, then run abort a transaction with transaction and a newly created “AbortError” DOMException and terminate these steps. This is done even if event’s canceled flag is false.

NOTE: This means that if an error event is fired and any of the event handlers throw an exception, transaction’s error property is set to an AbortError rather than request’s error, even if preventDefault() is never called. 2942. If event’s canceled flag is false, then run abort a transaction using transaction and request’s error, and terminate these steps. 2943. If transaction’s request list is empty, then run commit a transaction with transaction.

5.11. Clone a value

To make a clone of value in targetRealm during transaction, run these steps:

  1. Assert: transaction’s state is active.
  2. Set transaction’s state to inactive.

NOTE: The transaction is made inactive so that getters or other side effects triggered by the cloning operation are unable to make additional requests against the transaction. 2948. Let serialized be ?StructuredSerializeForStorage(value). 2949. Let clone be ?StructuredDeserialize(serialized, targetRealm). 2950. Set transaction’s state to active. 2951. Return clone.

6. Database operations

This section describes various operations done on the data in object stores and indexes in a database. These operations are run by the steps to asynchronously execute a request.

NOTE: Invocations of StructuredDeserialize() in the operation steps below can be asserted not to throw (as indicated by the ! prefix) because they operate only on previous output of StructuredSerializeForStorage().

6.1. Object store storage operation

To store a record into an object store with store, value, an optional key, and a no-overwrite flag, run these steps:

  1. If store uses a key generator, then:
  2. If key is undefined, then:
  3. Let key be the result of generating a key for store.
  4. If key is failure, then this operation failed with a “ConstraintError” DOMException. Abort this algorithm without taking any further steps.
  5. If store also uses in-line keys, then run inject a key into a value using a key path with value, key and store’s key path.
  6. Otherwise, run possibly update the key generator for store with key.
  7. If the no-overwrite flag was given to these steps and is true, and a record already exists in store with its key equal tokey, then this operation failed with a “ConstraintError” DOMException. Abort this algorithm without taking any further steps.
  8. If a record already exists in store with its key equal tokey, then remove the record from store using delete records from an object store.
  9. Store a record in store containing key as its key and !StructuredSerializeForStorage(value) as its value. The record is stored in the object store’s list of records such that the list is sorted according to the key of the records in ascending order.
  10. For each index which referencesstore:
  11. Let index key be the result of extracting a key from a value using a key path with value, index’s key path, and index’s multiEntry flag.
  12. If index key is an exception, or invalid, or failure, take no further actions for index, and continue these steps for the next index.

NOTE: An exception thrown in this step is not rethrown. 2969. If index’s multiEntry flag is false, or if index key is not an array key, and if index already contains a record with keyequal toindex key, and index’s unique flag is true, then this operation failed with a “ConstraintError” DOMException. Abort this algorithm without taking any further steps. 2970. If index’s multiEntry flag is true and index key is an array key, and if index already contains a record with keyequal to any of the subkeys of index key, and index’s unique flag is true, then this operation failed with a “ConstraintError” DOMException. Abort this algorithm without taking any further steps. 2971. If index’s multiEntry flag is false, or if index key is not an array key then store a record in index containing index key as its key and key as its value. The record is stored in index’s list of records such that the list is sorted primarily on the records keys, and secondarily on the records values, in ascending order. 2972. If index’s multiEntry flag is true and index key is an array key, then for each subkey of the subkeys of index key store a record in index containing subkey as its key and key as its value. The records are stored in index’s list of records such that the list is sorted primarily on the records keys, and secondarily on the records values, in ascending order.

NOTE: It is valid for there to be no subkeys. In this case no records are added to the index.

NOTE: Even if any member of subkeys is itself an array key, the member is used directly as the key for the index record. Nested array keys are not flattened or “unpacked” to produce multiple rows; only the outer-most array key is. 2973. Return key.

6.2. Object store retrieval operations

To retrieve a value from an object store with targetRealm, store and range, run these steps. They return undefined, an ECMAScript value, or an error (a DOMException):

  1. Let record be the first record in store’s list of records whose key is inrange, if any.

  2. If record was not found, return undefined.

  3. Let serialized be record’s value. If an error occurs while reading the value from the underlying storage, return a newly created “NotReadableError” DOMException.

  4. Return !StructuredDeserialize(serialized, targetRealm). To retrieve multiple values from an object store with targetRealm, store, range and optional count, run these steps. They return a sequence<any> or an error (a DOMException):

  5. If count is not given or is 0 (zero), let count be infinity.

  6. Let records be a list containing the first countrecords in store’s list of records whose key is inrange.

  7. Let list be an empty list.

  8. For eachrecord of records:

  9. Let serialized be record’s value. If an error occurs while reading the value from the underlying storage, return a newly created “NotReadableError” DOMException.

  10. Let entry be !StructuredDeserialize(serialized, targetRealm).

  11. Append entry to list.

  12. Return list converted to a sequence<any>. To retrieve a key from an object store with store and range, run these steps:

  13. Let record be the first record in store’s list of records whose key is inrange, if any.

  14. If record was not found, return undefined.

  15. Return the result of converting a key to a value with record’s key. To retrieve multiple keys from an object store with store, range and optional count, run these steps:

  16. If count is not given or is 0 (zero), let count be infinity.

  17. Let records be a list containing the first countrecords in store’s list of records whose key is inrange.

  18. Let list be an empty list.

  19. For eachrecord of records:

  20. Let entry be the result of converting a key to a value with record’s key.

  21. Append entry to list.

  22. Return list converted to a sequence<any>.

6.3. Index retrieval operations

To retrieve a referenced value from an index with targetRealm, index and range, run these steps:

  1. Let record be the first record in index’s list of records whose key is inrange, if any.

  2. If record was not found, return undefined.

  3. Let serialized be record’s referenced value.

  4. Return !StructuredDeserialize(serialized, targetRealm). To retrieve multiple referenced values from an index with targetRealm, index, range and optional count, run these steps:

  5. If count is not given or is 0 (zero), let count be infinity.

  6. Let records be a list containing the first countrecords in index’s list of records whose key is inrange.

  7. Let list be an empty list.

  8. For eachrecord of records:

  9. Let serialized be record’s referenced value.

  10. Let entry be !StructuredDeserialize(serialized, targetRealm).

  11. Append entry to list.

  12. Return list converted to a sequence<any>. NOTE: The values of an record in an index are the keys of records in the referenced object store.

To retrieve a value from an index with index and range, run these steps:

  1. Let record be the first record in index’s list of records whose key is inrange, if any.

  2. If record was not found, return undefined.

  3. Return the result of converting a key to a value with record’s value. To retrieve multiple values from an index with index, range and optional count, run these steps:

  4. If count is not given or is 0 (zero), let count be infinity.

  5. Let records be a list containing the first countrecords in index’s list of records whose key is inrange.

  6. Let list be an empty list.

  7. For eachrecord of records:

  8. Let entry be the result of converting a key to a value with record’s value.

  9. Append entry to list.

  10. Return list converted to a sequence<any>.

6.4. Object store deletion operation

To delete records from an object store with store and range, run these steps:

  1. Remove all records, if any, from store’s list of records with key inrange.
  2. For each index which referencesstore, remove every record from index’s list of records whose value is inrange, if any such records exist.
  3. Return undefined.

6.5. Record counting operation

To count the records in a range with source and range, run these steps:

  1. Let count be the number of records, if any, in source’s list of records with key inrange.
  2. Return count.

6.6. Object store clear operation

To clear an object store with store, run these steps:

  1. Remove all records from store.
  2. In all indexes which referencestore, remove all records.
  3. Return undefined.

6.7. Cursor iteration operation

To iterate a cursor with targetRealm, cursor, an optional key and primaryKey to iterate to, and an optional count, run these steps:

  1. Let source be cursor’s source.
  2. Let direction be cursor’s direction.
  3. Assert: if primaryKey is given, source is an index and direction is “next” or “prev”.
  4. Let records be the list of records in source.

NOTE:records is always sorted in ascendingkey order. In the case of source being an index, records is secondarily sorted in ascendingvalue order (where the value in an index is the key of the record in the referenced object store). 3049. Let range be cursor’s range. 3050. Let position be cursor’s position. 3051. Let object store position be cursor’s object store position. 3052. If count is not given, let count be 1. 3053. While count is greater than 0: 3054. Switch on direction:

“next” Let found record be the first record in records which satisfy all of the following requirements:

  • If key is defined, the record’s key is greater than or equal tokey.

  • If primaryKey is defined, the record’s key is equal tokey and the record’s value is greater than or equal toprimaryKey, or the record’s key is greater thankey.

  • If position is defined, and source is an object store, the record’s key is greater thanposition.

  • If position is defined, and source is an index, the record’s key is equal toposition and the record’s value is greater thanobject store position or the record’s key is greater thanposition.

  • The record’s key is inrange.

“nextunique” Let found record be the first record in records which satisfy all of the following requirements:

  • If key is defined, the record’s key is greater than or equal tokey.

  • If position is defined, the record’s key is greater thanposition.

  • The record’s key is inrange.

“prev” Let found record be the last record in records which satisfy all of the following requirements:

  • If key is defined, the record’s key is less than or equal tokey.

  • If primaryKey is defined, the record’s key is equal tokey and the record’s value is less than or equal toprimaryKey, or the record’s key is less thankey.

  • If position is defined, and source is an object store, the record’s key is less thanposition.

  • If position is defined, and source is an index, the record’s key is equal toposition and the record’s value is less thanobject store position or the record’s key is less thanposition.

  • The record’s key is inrange.

“prevunique” Let temp record be the last record in records which satisfy all of the following requirements:

  • If key is defined, the record’s key is less than or equal tokey.

  • If position is defined, the record’s key is less thanposition.

  • The record’s key is inrange.

If temp record is defined, let found record be the first record in records whose key is equal totemp record’s key.

NOTE: Iterating with “prevunique” visits the same records that “nextunique” visits, but in reverse order. 3055. If found record is not defined, then: 3056. Set cursor’s key to undefined. 3057. If source is an index, set cursor’s object store position to undefined. 3058. If cursor’s key only flag is false, set cursor’s value to undefined. 3059. Return null. 3060. Let position be found record’s key. 3061. If source is an index, let object store position be found record’s value. 3062. Decrease count by 1. 3063. Set cursor’s position to position. 3064. If source is an index, set cursor’s object store position to object store position. 3065. Set cursor’s key to found record’s key. 3066. If cursor’s key only flag is false, then: 3067. Let serialized be found record’s referenced value. 3068. Set cursor’s value to !StructuredDeserialize(serialized, targetRealm) 3069. Set cursor’s got value flag to true. 3070. Return cursor.

7. ECMAScript binding

This section defines how key values defined in this specification are converted to and from ECMAScript values, and how they may be extracted from and injected into ECMAScript values using key paths. This section references types and algorithms and uses some algorithm conventions from the ECMAScript Language Specification. ECMA-262 Conversions not detailed here are defined in WEBIDL.

7.1. Extract a key from a value

To extract a key from a value using a key path with value, keyPath and an optional multiEntry flag, run the following steps. The result of these steps is a key, invalid, or failure, or the steps may throw an exception.

  1. Let r be the result of evaluating a key path on a value with value and keyPath. Rethrow any exceptions.

  2. If r is failure, return failure.

  3. Let key be the result of converting a value to a key with r if the multiEntry flag is false, and the result of converting a value to a multiEntry key with r otherwise. Rethrow any exceptions.

  4. If key is invalid, return invalid.

  5. Return key. To evaluate a key path on a value with value and keyPath, run the following steps. The result of these steps is an ECMAScript value or failure, or the steps may throw an exception.

  6. If keyPath is a list of strings, then:

  7. Let result be a new Array object created as if by the expression .

  8. Let i be 0.

  9. For eachitem of keyPath:

  10. Let key be the result of recursively evaluating a key path on a value with item and value.

  11. Assert: key is not an abrupt completion.

  12. If key is failure, abort the overall algorithm and return failure.

  13. Let p be !ToString(i).

  14. Let status be CreateDataProperty(result, p, key).

  15. Assert: status is true.

  16. Increase i by 1.

  17. Return result.

NOTE: This will only ever “recurse” one level since key path sequences can’t ever be nested. 3093. If keyPath is the empty string, return value and skip the remaining steps. 3094. Let identifiers be the result of strictly splittingkeyPath on U+002E FULL STOP characters (.). 3095. For eachidentifier of identifiers, jump to the appropriate step below:

If Type(value) is String, and identifier is “length” Let value be a Number equal to the number of elements in value.

If value is an Array and identifier is “length” Let value be !ToLength(!Get(value, “length”)).

If value is a Blob and identifier is “size” Let value be a Number equal to value’s size.

If value is a Blob and identifier is “type” Let value be a String equal to value’s type.

If value is a File and identifier is “name” Let value be a String equal to value’s name.

If value is a File and identifier is “lastModified” Let value be a Number equal to value’s lastModified.

Otherwise 3096. If Type(value) is not Object, return failure. 3097. Let hop be !HasOwnProperty(value, identifier). 3098. If hop is false, return failure. 3099. Let value be !Get(value, identifier). 3100. If value is undefined, return failure. 3101. Assert: value is not an abrupt completion. 3102. Return value. NOTE: Assertions can be made in the above steps because this algorithm is only applied to values that are the output of StructuredDeserialize and only access “own” properties.

7.2. Inject a key into a value

NOTE: The key paths used in this section are always strings and never sequences, since it is not possible to create a object store which has a key generator and also has a key path that is a sequence.

To check that a key could be injected into a value with value and a keyPath, run the following steps. The result of these steps is either true or false.

  1. Let identifiers be the result of strictly splittingkeyPath on U+002E FULL STOP characters (.).
  2. Assert: identifiers is not empty.
  3. Remove the last item of identifiers.
  4. For each remaining identifier of identifiers, if any:
  5. If value is not an Object or an Array, return false.
  6. Let hop be !HasOwnProperty(value, identifier).
  7. If hop is false, return true.
  8. Let value be !Get(value, identifier).
  9. Return true if value is an Object or an Array, or false otherwise. NOTE: Assertions can be made in the above steps because this algorithm is only applied to values that are the output of StructuredDeserialize.

To inject a key into a value using a key path with value, a key and a keyPath, run these steps:

  1. Let identifiers be the result of strictly splittingkeyPath on U+002E FULL STOP characters (.).
  2. Assert: identifiers is not empty.
  3. Let last be the last item of identifiers and remove it from the list.
  4. For each remaining identifier of identifiers:
  5. Assert: value is an Object or an Array.
  6. Let hop be !HasOwnProperty(value, identifier).
  7. If hop is false, then:
  8. Let o be a new Object created as if by the expression ({}).
  9. Let status be CreateDataProperty(value, identifier, o).
  10. Assert: status is true.
  11. Let value be !Get(value, identifier).
  12. Assert: value is an Object or an Array.
  13. Let keyValue be the result of converting a key to a value with key.
  14. Let status be CreateDataProperty(value, last, keyValue).
  15. Assert: status is true. NOTE: Assertions can be made in the above steps because this algorithm is only applied to values that are the output of StructuredDeserialize, and the steps to check that a key could be injected into a value have been run.

7.3. Convert a key to a value

To convert a key to a value with key, run the following steps. The steps return an ECMAScript value.

  1. Let type be key’s type.
  2. Let value be key’s value.
  3. Switch on type:

numberReturn an ECMAScript Number value equal to value

stringReturn an ECMAScript String value equal to value

date 3139. Let date be the result of executing the ECMAScript Date constructor with the single argument value. 3140. Assert: date is not an abrupt completion. 3141. Return date. binary3143. Let len be value’s length. 3144. Let buffer be the result of executing the ECMAScript ArrayBuffer constructor with len. 3145. Assert: buffer is not an abrupt completion. 3146. Set the entries in buffer’s ArrayBufferData internal slot to the entries in value. 3147. Return buffer. array3149. Let array be the result of executing the ECMAScript Array constructor with no arguments. 3150. Assert: array is not an abrupt completion. 3151. Let len be value’s size. 3152. Let index be 0. 3153. While index is less than len: 3154. Let entry be the result of converting a key to a value with valueindex. 3155. Let status be CreateDataProperty(array, index, entry). 3156. Assert: status is true. 3157. Increase index by 1. 3158. Return array.

7.4. Convert a value to a key

To convert a value to a key with an ECMAScript value input, and an optional setseen, run the following steps. The result of these steps is a key or invalid, or the steps may throw an exception.

  1. If seen was not given, then let seen be a new empty set.
  2. If seencontainsinput, then return invalid.
  3. Jump to the appropriate step below:

If Type(input) is Number 3164. If input is NaN then return invalid. 3165. Otherwise, return a new key with typenumber and valueinput. If input is a Date (has a DateValue internal slot) 3167. Let ms be the value of input’s DateValue internal slot. 3168. If ms is NaN then return invalid. 3169. Otherwise, return a new key with typedate and valuems. If Type(input) is String 3171. Return a new key with typestring and valueinput. If input is a buffer source type3173. Let bytes be the result of getting a copy of the bytes held by the buffer sourceinput. Rethrow any exceptions. 3174. Return a new key with typebinary and valuebytes. If input is an Array exotic object3176. Let len be ?ToLength( ?Get(input, “length”)). 3177. Appendinput to seen. 3178. Let keys be a new empty list. 3179. Let index be 0. 3180. While index is less than len: 3181. Let hop be ?HasOwnProperty(input, index). 3182. If hop is false, return invalid. 3183. Let entry be ?Get(input, index). 3184. Let key be the result of converting a value to a key with arguments entry and seen. 3185. ReturnIfAbrupt(key). 3186. If key is invalid abort these steps and return invalid. 3187. Appendkey to keys. 3188. Increase index by 1. 3189. Return a new array key with valuekeys. Otherwise Return invalid.

To convert a value to a multiEntry key with an ECMAScript value input, run the following steps. The result of these steps is a key or invalid, or the steps may throw an exception.

  1. If input is an Array exotic object, then:
  2. Let len be ? ToLength( ?Get(input, “length”)).
  3. Let seen be a new set containing only input.
  4. Let keys be a new empty list.
  5. Let index be 0.
  6. While index is less than len:
  7. Let entry be Get(input, index).
  8. If entry is not an abrupt completion, then:
  9. Let key be the result of converting a value to a key with arguments entry and seen.
  10. If key is not invalid or an abrupt completion, and there is no item in keysequal tokey, then appendkey to keys.
  11. Increase index by 1.
  12. Return a new array key with value set to keys.
  13. Otherwise, return the result of converting a value to a key with argument input. Rethrow any exceptions. NOTE: These steps are similar to those to convert a value to a key but if the top-level value is an Array then members which can not be converted to keys are ignored, and duplicates are removed.

For example, the value 10, 20, null, 30, 20 is converted to an array key with subkeys 10, 20, 30.

8. Privacy considerations

This section is non-normative.

8.1. User tracking

A third-party host (or any object capable of getting content distributed to multiple sites) could use a unique identifier stored in its client-side database to track a user across multiple sessions, building a profile of the user’s activities. In conjunction with a site that is aware of the user’s real id object (for example an e-commerce site that requires authenticated credentials), this could allow oppressive groups to target individuals with greater accuracy than in a world with purely anonymous Web usage.

There are a number of techniques that can be used to mitigate the risk of user tracking:

Blocking third-party storage User agents may restrict access to the database objects to scripts originating at the domain of the top-level document of the browsing context, for instance denying access to the API for pages from other domains running in iframes.

Expiring stored data User agents may automatically delete stored data after a period of time.

This can restrict the ability of a site to track a user, as the site would then only be able to track the user across multiple sessions when she authenticates with the site itself (e.g. by making a purchase or logging in to a service).

However, this also puts the user’s data at risk.

Treating persistent storage as cookies User agents should present the database feature to the user in a way that associates them strongly with HTTP session cookies. COOKIES

This might encourage users to view such storage with healthy suspicion.

Site-specific safe-listing of access to databases User agents may require the user to authorize access to databases before a site can use the feature.

Attribution of third-party storage User agents may record the origins of sites that contained content from third-party origins that caused data to be stored.

If this information is then used to present the view of data currently in persistent storage, it would allow the user to make informed decisions about which parts of the persistent storage to prune. Combined with a blocklist (“delete this data and prevent this domain from ever storing data again”), the user can restrict the use of persistent storage to sites that she trusts.

Shared blocklists User agents may allow users to share their persistent storage domain blocklists.

This would allow communities to act together to protect their privacy.

While these suggestions prevent trivial use of this API for user tracking, they do not block it altogether. Within a single domain, a site can continue to track the user during a session, and can then pass all this information to the third party along with any identifying information (names, credit card numbers, addresses) obtained by the site. If a third party cooperates with multiple sites to obtain such information, a profile can still be created.

However, user tracking is to some extent possible even with no cooperation from the user agent whatsoever, for instance by using session identifiers in URLs, a technique already commonly used for innocuous purposes but easily repurposed for user tracking (even retroactively). This information can then be shared with other sites, using visitors’ IP addresses and other user-specific data (e.g. user-agent headers and configuration settings) to combine separate sessions into coherent user profiles.

If the user interface for persistent storage presents data in the persistent storage features described in this specification separately from data in HTTP session cookies, then users are likely to delete data in one and not the other. This would allow sites to use the two features as redundant backup for each other, defeating a user’s attempts to protect his privacy.

8.3. Sensitivity of data

User agents should treat persistently stored data as potentially sensitive; it is quite possible for e-mails, calendar appointments, health records, or other confidential documents to be stored in this mechanism.

To this end, user agents should ensure that when deleting data, it is promptly deleted from the underlying storage.

9. Security considerations

9.1. DNS spoofing attacks

Because of the potential for DNS spoofing attacks, one cannot guarantee that a host claiming to be in a certain domain really is from that domain. To mitigate this, pages can use TLS. Pages using TLS can be sure that only pages using TLS that have certificates identifying them as being from the same domain can access their databases.

9.2. Cross-directory attacks

Different authors sharing one host name, for example users hosting content on geocities.com, all share one set of databases.

There is no feature to restrict the access by pathname. Authors on shared hosts are therefore recommended to avoid using these features, as it would be trivial for other authors to read the data and overwrite it.

NOTE: Even if a path-restriction feature was made available, the usual DOM scripting security model would make it trivial to bypass this protection and access the data from any path.

9.3. Implementation risks

The two primary risks when implementing these persistent storage features are letting hostile sites read information from other domains, and letting hostile sites write information that is then read from other domains.

Letting third-party sites read data that is not supposed to be read from their domain causes information leakage, For example, a user’s shopping wish list on one domain could be used by another domain for targeted advertising; or a user’s work-in-progress confidential documents stored by a word-processing site could be examined by the site of a competing company.

Letting third-party sites write data to the persistent storage of other domains can result in information spoofing, which is equally dangerous. For example, a hostile site could add records to a user’s wish list; or a hostile site could set a user’s session identifier to a known ID that the hostile site can then use to track the user’s actions on the victim site.

Thus, strictly following the storage key partitioning model described in this specification is important for user security.

If host names or database names are used to construct paths for persistence to a file system they must be appropriately escaped to prevent an adversary from accessing information from other storage keys using relative paths such as “../”.

9.4. Persistence risks

Practical implementations will persist data to a non-volatile storage medium. Data will be serialized when stored and deserialized when retrieved, although the details of the serialization format will be user-agent specific. User agents are likely to change their serialization format over time. For example, the format may be updated to handle new data types, or to improve performance. To satisfy the operational requirements of this specification, implementations must therefore handle older serialization formats in some way. Improper handling of older data can result in security issues. In addition to basic serialization concerns, serialized data could encode assumptions which are not valid in newer versions of the user agent.

A practical example of this is the RegExp type. The StructuredSerializeForStorage operation allows serializing RegExp objects. A typical user agent will compile a regular expression into native machine instructions, with assumptions about how the input data is passed and results returned. If this internal state was serialized as part of the data stored to the database, various problems could arise when the internal representation was later deserialized. For example, the means by which data was passed into the code could have changed. Security bugs in the compiler output could have been identified and fixed in updates to the user agent, but remain in the serialized internal state.

User agents must identify and handle older data appropriately. One approach is to include version identifiers in the serialization format, and to reconstruct any internal state from script-visible state when older data is encountered.

10. Accessibility considerations

This section is non-normative.

The API described by this specification has limited accesibility considerations:

  • It does not provide for visual rendering of content, or control over color.
  • It does not provide features to accept user input.
  • It does not provide user interaction features.
  • It does not define document semantics.
  • It does not provide time-based visual media.
  • It does not allow time limits.
  • It does not directly provide content for end-users, either in textual, graphical or other or non-textual form.
  • It does not define a transmission protocol.

The API does allow storage of structured content. Textual content can be stored as strings. Support exists in the API for developers to store alternative non-textual content such as images or audio as Blob, File, or ImageData objects. Developers producing dynamic content applications using the API should ensure that the content is accessible to users with a variety of technologies and needs.

While the API itself does not define a specific mechanism for it, storage of structured content also allows developers to store internationalized content, using different records or structure within records to hold language alternatives.

The API does not define or require any a user agent to generate a user interface to enable interaction with the API. User agents may optionally provide user interface elements to support the API. Examples include prompts to users when additional storage quota is required, functionality to observe storage used by particular web sites, or tools specific to the API’s storage such as inspecting, modifying, or deleting records. Any such user interface elements must be designed with accessibility tools in mind. For example, a user interface presenting the fraction of storage quota used in graphical form must also provide the same data to tools such as screen readers.

11. Revision history

This section is non-normative.

The following is an informative summary of the changes since the last publication of this specification. A complete revision history can be found here. For the revision history of the first edition, see that document’s Revision History. For the revision history of the second edition, see that document’s Revision History.

  • The cleanup Indexed Database transactions algorithm now returns a value for integration with other specs. (PR #232)
  • Updated partial interface definition since WindowOrWorkerGlobalScope is now a mixin (PR #238).
  • Added databases() method. (Issue #31)
  • Added commit() method. (Issue #234)
  • Added request attribute. (Issue #255)
  • Removed handling for nonstandard lastModifiedDate property of File objects. (Issue #215)
  • Remove escaping includes() method. (Issue #294)
  • Restrict array keys to Array exotic objects (i.e. disallow proxies). (Issue #309)
  • Transactions are now temporarily made inactive during clone operations.
  • Added durability option and durability attribute. (Issue #50)
  • Specified § 2.7.2 Transaction scheduling more precisely and disallow starting read/write transactions while read-only transactions with overlapping scope are running. (Issue #253)
  • Added Accessibility considerations section. (Issue #327)
  • Used infra’s list sorting definition. (Issue #346)
  • Added a definition for live transactions, and renamed “run an upgrade transaction” to upgrade a database, to disambiguate “running”. (Issue #408)
  • Specified the DOMException type for failures when reading a value from the underlying storage in § 6.2 Object store retrieval operations. (Issue #423)

12. Acknowledgements

This section is non-normative.

Special thanks to Nikunj Mehta, the original author of the first edition, and Jonas Sicking, Eliot Graff, Andrei Popescu, and Jeremy Orlow, additional editors of the first edition.

Garret Swart was extremely influential in the design of this specification.

Thanks to Tab Atkins, Jr. for creating and maintaining Bikeshed, the specification authoring tool used to create this document, and for his general authoring advice.

Special thanks to Abhishek Shanthkumar, Adam Klein, Addison Phillips, Adrienne Walker, Alec Flett, Andrea Marchesini, Andreas Butler, Andrew Sutherland, Anne van Kesteren, Anthony Ramine, Ari Chivukula, Arun Ranganathan, Ben Dilts, Ben Turner, Bevis Tseng, Boris Zbarsky, Brett Zamir, Chris Anderson, Dana Florescu, Danillo Paiva, David Grogan, Domenic Denicola, Dominique Hazael-Massieux, Evan Stade, Glenn Maynard, Hans Wennborg, Isiah Meadows, Israel Hilerio, Jake Archibald, Jake Drew, Jerome Hode, Josh Matthews, João Eiras, Kagami Sascha Rosylight, Kang-Hao Lu, Kris Zyp, Kristof Degrave, Kyaw Tun, Kyle Huey, Laxminarayan G Kamath A, Maciej Stachowiak, Marcos Cáceres, Margo Seltzer, Marijn Kruisselbrink, Ms2ger, Odin Omdal, Olli Pettay, Pablo Castro, Philip Jägenstedt, Shawn Wilsher, Simon Pieters, Tobie Langel, Victor Costan, Xiaoqian Wu, Yannic Bonenberger, Yaron Tausky, Yonathan Randolph, and Zhiqiang Zhang, all of whose feedback and suggestions have led to improvements to this specification.

Conformance

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. RFC2119

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class=“example”, like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class=“note”, like this:

Note, this is an informative note.

Conformant Algorithms

Requirements phrased in the imperative as part of algorithms (such as “strip any leading space characters” or “return false and abort these steps”) are to be interpreted with the meaning of the key word (“must”, “should”, “may”, etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Document conventions

Conformance requirements are expressed with a combination of descriptive assertions and RFC 2119 terminology. The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in the normative parts of this document are to be interpreted as described in RFC 2119. However, for readability, these words do not appear in all uppercase letters in this specification.

All of the text of this specification is normative except sections explicitly marked as non-normative, examples, and notes. RFC2119

Examples in this specification are introduced with the words “for example” or are set apart from the normative text with class=“example”, like this:

This is an example of an informative example.

Informative notes begin with the word “Note” and are set apart from the normative text with class=“note”, like this:

Note, this is an informative note.

Conformant Algorithms

Requirements phrased in the imperative as part of algorithms (such as “strip any leading space characters” or “return false and abort these steps”) are to be interpreted with the meaning of the key word (“must”, “should”, “may”, etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Requirements phrased in the imperative as part of algorithms (such as “strip any leading space characters” or “return false and abort these steps”) are to be interpreted with the meaning of the key word (“must”, “should”, “may”, etc) used in introducing the algorithm.

Conformance requirements phrased as algorithms or specific steps can be implemented in any manner, so long as the end result is equivalent. In particular, the algorithms defined in this specification are intended to be easy to understand and are not intended to be performant. Implementers are encouraged to optimize.

Index

Terms defined by this specification

  • abort

  • dfn for transaction, in § 2.7.1

  • event for IDBTransaction, in § 2.7.1

  • abort(), in § 4.9

  • abort an upgrade transaction, in § 5.8

  • abort a transaction, in § 5.5

  • aborted, in § 2.7.1

  • aborting, in § 2.7.1

  • active, in § 2.7.1

  • add or put, in § 4.5

  • add(value), in § 4.5

  • add(value, key), in § 4.5

  • advance(count), in § 4.8

  • array key, in § 2.4

  • ascending, in § 2.4

  • asynchronously execute a request, in § 5.6

  • autoIncrement

  • attribute for IDBObjectStore, in § 4.5

  • dict-member for IDBObjectStoreParameters, in § 4.4

  • blocked, in § 2.8.1

  • bound(lower, upper), in § 4.7

  • bound(lower, upper, lowerOpen), in § 4.7

  • bound(lower, upper, lowerOpen, upperOpen), in § 4.7

  • check that a key could be injected into a value, in § 7.2

  • cleanup event loop, in § 2.7

  • cleanup Indexed Database transactions, in § 2.7.1

  • clear(), in § 4.5

  • clear an object store, in § 6.6

  • clone, in § 5.11

  • close, in § 2.1.1

  • close(), in § 4.4

  • close a database connection, in § 5.2

  • closed, in § 2.1.1

  • close pending flag, in § 2.1.1

  • cmp(first, second), in § 4.3

  • commit, in § 2.7.1

  • commit(), in § 4.9

  • commit a transaction, in § 5.4

  • committed, in § 2.7.1

  • committing, in § 2.7.1

  • compare two keys, in § 2.4

  • complete, in § 2.7.1

  • connected, in § 2.1.1

  • connection

  • definition of, in § 2.1.1

  • dfn for transaction, in § 2.7

  • connection queue, in § 2.8.2

  • constructor(type), in § 4.2

  • constructor(type, eventInitDict), in § 4.2

  • containing only, in § 2.9

  • continue(), in § 4.8

  • continue(key), in § 4.8

  • continuePrimaryKey(key, primaryKey), in § 4.8

  • convert a key to a value, in § 7.3

  • convert a value to a key, in § 7.4

  • convert a value to a key range, in § 2.9

  • convert a value to a multiEntry key, in § 7.4

  • count()

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • count(query)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • count the records in a range, in § 6.5

  • create a sorted name list, in § 2

  • created, in § 2.7.1

  • createIndex(name, keyPath), in § 4.5

  • createIndex(name, keyPath, options), in § 4.5

  • createObjectStore(name), in § 4.4

  • createObjectStore(name, options), in § 4.4

  • current number, in § 2.11

  • cursor, in § 2.10

  • database, in § 2.1

  • database access task source, in § 4

  • databases(), in § 4.3

  • db, in § 4.9

  • “default”, in § 4.4

  • delete(), in § 4.8

  • delete a database, in § 5.3

  • deleteDatabase(name), in § 4.3

  • deleteIndex(name), in § 4.5

  • deleteObjectStore(name), in § 4.4

  • delete(query), in § 4.5

  • delete records from an object store, in § 6.4

  • direction

  • attribute for IDBCursor, in § 4.8

  • dfn for cursor, in § 2.10

  • “done”, in § 4.1

  • done flag, in § 2.8

  • durability

  • attribute for IDBTransaction, in § 4.9

  • dict-member for IDBTransactionOptions, in § 4.4

  • durability hint, in § 2.7

  • effective key, in § 2.10

  • effective object store, in § 2.10

  • equal to, in § 2.4

  • error

  • attribute for IDBRequest, in § 4.1

  • attribute for IDBTransaction, in § 4.9

  • dfn for request, in § 2.8

  • dfn for transaction, in § 2.7

  • event for IDBRequest, in § 2.8

  • evaluate a key path on a value, in § 7.1

  • extract a key from a value using a key path, in § 7.1

  • finished, in § 2.7.1

  • fire an error event, in § 5.10

  • fire a success event, in § 5.9

  • fire a version change event, in § 4.2

  • generate a key, in § 2.11

  • getAll()

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • getAllKeys()

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • getAllKeys(query)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • getAllKeys(query, count)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • getAll(query)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • getAll(query, count)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • getKey(query)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • get(query)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • got value flag, in § 2.10

  • greater than, in § 2.4

  • IDBCursor, in § 4.8

  • IDBCursorDirection, in § 4.8

  • IDBCursorWithValue, in § 4.8

  • IDBDatabase, in § 4.4

  • IDBDatabaseInfo, in § 4.3

  • IDBFactory, in § 4.3

  • IDBIndex, in § 4.6

  • IDBIndexParameters, in § 4.5

  • IDBKeyRange, in § 4.7

  • IDBObjectStore, in § 4.5

  • IDBObjectStoreParameters, in § 4.4

  • IDBOpenDBRequest, in § 4.1

  • IDBRequest, in § 4.1

  • IDBRequestReadyState, in § 4.1

  • IDBTransaction, in § 4.9

  • IDBTransactionDurability, in § 4.4

  • IDBTransactionMode, in § 4.9

  • IDBTransactionOptions, in § 4.4

  • IDBVersionChangeEvent, in § 4.2

  • IDBVersionChangeEventInit, in § 4.2

  • IDBVersionChangeEvent(type), in § 4.2

  • IDBVersionChangeEvent(type, eventInitDict), in § 4.2

  • identifier, in § 2.5

  • in, in § 2.9

  • inactive, in § 2.7.1

  • includes(key), in § 4.7

  • index

  • definition of, in § 2.6

  • dfn for index-handle, in § 2.6.1

  • indexedDB, in § 4.3

  • index handle, in § 2.6.1

  • index(name), in § 4.5

  • indexNames, in § 4.5

  • index set, in § 2.2.1

  • inject a key into a value using a key path, in § 7.2

  • in-line keys, in § 2.2

  • iterate a cursor, in § 6.7

  • key

  • attribute for IDBCursor, in § 4.8

  • definition of, in § 2.4

  • dfn for cursor, in § 2.10

  • key generator, in § 2.11

  • key only flag, in § 2.10

  • key path

  • definition of, in § 2.5

  • dfn for index, in § 2.6

  • dfn for object-store, in § 2.2

  • keyPath

  • attribute for IDBIndex, in § 4.6

  • attribute for IDBObjectStore, in § 4.5

  • dict-member for IDBObjectStoreParameters, in § 4.4

  • key range, in § 2.9

  • keys, in § 2.6

  • less than, in § 2.4

  • lifetime, in § 2.7.1

  • list of records

  • dfn for index, in § 2.6

  • dfn for object-store, in § 2.2

  • live, in § 2.7.1

  • lower, in § 4.7

  • lower bound, in § 2.9

  • lowerBound(lower), in § 4.7

  • lowerBound(lower, open), in § 4.7

  • lowerOpen, in § 4.7

  • lower open flag, in § 2.9

  • mode

  • attribute for IDBTransaction, in § 4.9

  • dfn for transaction, in § 2.7

  • multiEntry

  • attribute for IDBIndex, in § 4.6

  • dict-member for IDBIndexParameters, in § 4.5

  • multiEntry flag, in § 2.6

  • name

  • attribute for IDBDatabase, in § 4.4

  • attribute for IDBIndex, in § 4.6

  • attribute for IDBObjectStore, in § 4.5

  • definition of, in § 2

  • dfn for database, in § 2.1

  • dfn for index, in § 2.6

  • dfn for index-handle, in § 2.6.1

  • dfn for object-store, in § 2.2

  • dfn for object-store-handle, in § 2.2.1

  • dict-member for IDBDatabaseInfo, in § 4.3

  • newVersion

  • attribute for IDBVersionChangeEvent, in § 4.2

  • dict-member for IDBVersionChangeEventInit, in § 4.2

  • “next”, in § 4.8

  • “nextunique”, in § 4.8

  • object store

  • definition of, in § 2.2

  • dfn for object-store-handle, in § 2.2.1

  • objectStore, in § 4.6

  • object store handle

  • definition of, in § 2.2.1

  • dfn for index-handle, in § 2.6.1

  • objectStore(name), in § 4.9

  • objectStoreNames

  • attribute for IDBDatabase, in § 4.4

  • attribute for IDBTransaction, in § 4.9

  • object store position, in § 2.10

  • object store set, in § 2.1.1

  • oldVersion

  • attribute for IDBVersionChangeEvent, in § 4.2

  • dict-member for IDBVersionChangeEventInit, in § 4.2

  • onabort

  • attribute for IDBDatabase, in § 4.4

  • attribute for IDBTransaction, in § 4.9

  • onblocked, in § 4.1

  • onclose, in § 4.4

  • oncomplete, in § 4.9

  • onerror

  • attribute for IDBDatabase, in § 4.4

  • attribute for IDBRequest, in § 4.1

  • attribute for IDBTransaction, in § 4.9

  • only(value), in § 4.7

  • onsuccess, in § 4.1

  • onupgradeneeded, in § 4.1

  • onversionchange, in § 4.4

  • open a database connection, in § 5.1

  • openCursor()

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • openCursor(query)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • openCursor(query, direction)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • openKeyCursor()

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • openKeyCursor(query)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • openKeyCursor(query, direction)

  • method for IDBIndex, in § 4.6

  • method for IDBObjectStore, in § 4.5

  • open(name), in § 4.3

  • open(name, version), in § 4.3

  • open request, in § 2.8.1

  • out-of-line keys, in § 2.2

  • overlap, in § 2.7

  • overlapping scope, in § 2.7

  • “pending”, in § 4.1

  • placed, in § 2.8

  • position, in § 2.10

  • possibly update the key generator, in § 2.11

  • “prev”, in § 4.8

  • “prevunique”, in § 4.8

  • primaryKey, in § 4.8

  • processed, in § 2.8

  • processed flag, in § 2.8

  • put(value), in § 4.5

  • put(value, key), in § 4.5

  • range, in § 2.10

  • “readonly”, in § 4.9

  • read-only transaction, in § 2.7

  • “readwrite”, in § 4.9

  • read/write transaction, in § 2.7

  • readyState, in § 4.1

  • record, in § 2.2

  • records, in § 2.6

  • referenced, in § 2.6

  • referenced value, in § 2.6

  • references, in § 2.6

  • “relaxed”, in § 4.4

  • request

  • attribute for IDBCursor, in § 4.8

  • definition of, in § 2.8

  • dfn for cursor, in § 2.10

  • request list, in § 2.7

  • result

  • attribute for IDBRequest, in § 4.1

  • dfn for request, in § 2.8

  • retrieve a key from an object store, in § 6.2

  • retrieve a referenced value from an index, in § 6.3

  • retrieve a value from an index, in § 6.3

  • retrieve a value from an object store, in § 6.2

  • retrieve multiple keys from an object store, in § 6.2

  • retrieve multiple referenced values from an index, in § 6.3

  • retrieve multiple values from an index, in § 6.3

  • retrieve multiple values from an object store, in § 6.2

  • scope, in § 2.7

  • source

  • attribute for IDBCursor, in § 4.8

  • attribute for IDBRequest, in § 4.1

  • dfn for cursor, in § 2.10

  • dfn for request, in § 2.8

  • start, in § 2.7.1

  • started, in § 2.7.1

  • state, in § 2.7.1

  • store a record into an object store, in § 6.1

  • “strict”, in § 4.4

  • subkeys, in § 2.4

  • success, in § 2.8

  • transaction

  • attribute for IDBObjectStore, in § 4.5

  • attribute for IDBRequest, in § 4.1

  • definition of, in § 2.7

  • dfn for cursor, in § 2.10

  • dfn for index-handle, in § 2.6.1

  • dfn for object-store-handle, in § 2.2.1

  • dfn for request, in § 2.8

  • transaction(storeNames), in § 4.4

  • transaction(storeNames, mode), in § 4.4

  • transaction(storeNames, mode, options), in § 4.4

  • type, in § 2.4

  • unbounded key range, in § 2.9

  • unique

  • attribute for IDBIndex, in § 4.6

  • dict-member for IDBIndexParameters, in § 4.5

  • unique flag, in § 2.6

  • update(value), in § 4.8

  • upgrade a database, in § 5.7

  • upgradeneeded, in § 2.8.1

  • upgrade transaction

  • definition of, in § 2.7.3

  • dfn for database, in § 2.1

  • upper, in § 4.7

  • upper bound, in § 2.9

  • upperBound(upper), in § 4.7

  • upperBound(upper, open), in § 4.7

  • upperOpen, in § 4.7

  • upper open flag, in § 2.9

  • valid key path, in § 2.5

  • value

  • attribute for IDBCursorWithValue, in § 4.8

  • definition of, in § 2.3

  • dfn for cursor, in § 2.10

  • dfn for key, in § 2.4

  • values, in § 2.6

  • version

  • attribute for IDBDatabase, in § 4.4

  • dfn for connection, in § 2.1.1

  • dfn for database, in § 2.1

  • dict-member for IDBDatabaseInfo, in § 4.3

  • “versionchange”, in § 4.9

  • versionchange, in § 2.1.1

Terms defined by reference

  • DOM defines the following terms:

  • Document

  • Event

  • EventInit

  • EventTarget

  • bubbles

  • cancelable

  • canceled flag

  • creating an event

  • dispatch

  • event

  • fire an event

  • get the parent

  • preventDefault()

  • type

  • ECMA-262 defines the following terms:

  • !

  • ?

  • Array

  • CreateDataProperty

  • Date

  • Get

  • HasOwnProperty

  • Number

  • Object

  • RegExp

  • String

  • ToLength

  • ToString

  • abrupt completion

  • array exotic object

  • array exotic objects

  • IdentifierName

  • realm

  • ReturnIfAbrupt

  • sort(comparator)

  • the current Realm Record

  • Type

  • FileAPI defines the following terms:

  • Blob

  • File

  • lastModified

  • name

  • size

  • type

  • HTML defines the following terms:

  • DOMStringList

  • EventHandler

  • ImageData

  • StructuredDeserialize

  • StructuredSerializeForStorage

  • WindowOrWorkerGlobalScope

  • browsing context

  • domain

  • event handler event type

  • event handler IDL attribute

  • event loop

  • in parallel

  • origin

  • queue a task

  • relevant settings object

  • serializable object

  • task queues

  • INFRA defines the following terms:

  • append (for list)

  • append (for set)

  • assert

  • byte

  • byte less than

  • byte sequence

  • code unit less than

  • contain

  • for each

  • item

  • length

  • list

  • set

  • size

  • sort in ascending order

  • strictly split a string

  • string

  • STORAGE defines the following terms:

  • obtain a storage key

  • storage bucket

  • storage key

  • WEBIDL defines the following terms:

  • AbortError

  • ArrayBuffer

  • ConstraintError

  • DOMException

  • DOMString

  • DataCloneError

  • DataError

  • EnforceRange

  • Exposed

  • InvalidAccessError

  • InvalidStateError

  • NewObject

  • NotFoundError

  • NotReadableError

  • Promise

  • QuotaExceededError

  • ReadOnlyError

  • SameObject

  • SecurityError

  • SyntaxError

  • TransactionInactiveError

  • TypeError

  • Uint8Array

  • UnknownError

  • VersionError

  • a new promise

  • a promise rejected with

  • any

  • boolean

  • buffer source types

  • byte

  • create

  • get a copy of the buffer source

  • record

  • reject

  • resolve

  • sequence

  • short

  • the given value

  • this

  • throw

  • undefined

  • unrestricted double

  • unsigned long

  • unsigned long long

References

Normative References

DOM Anne van Kesteren. DOM Standard. Living Standard. URL: https://dom.spec.whatwg.org/ECMA-262 ECMAScript Language Specification. URL: https://tc39.es/ecma262/multipage/FileAPI Marijn Kruisselbrink. File API. 24 October 2024. WD. URL: https://www.w3.org/TR/FileAPI/HTML Anne van Kesteren; et al. HTML Standard. Living Standard. URL: https://html.spec.whatwg.org/multipage/INFRA Anne van Kesteren; Domenic Denicola. Infra Standard. Living Standard. URL: https://infra.spec.whatwg.org/RFC2119 S. Bradner. Key words for use in RFCs to Indicate Requirement Levels. March 1997. Best Current Practice. URL: https://datatracker.ietf.org/doc/html/rfc2119STORAGE Anne van Kesteren. Storage Standard. Living Standard. URL: https://storage.spec.whatwg.org/WEBIDL Edgar Chen; Timothy Gu. Web IDL Standard. Living Standard. URL: https://webidl.spec.whatwg.org/

Informative References

Charmod-Norm Addison Phillips; et al. Character Model for the World Wide Web: String Matching. 11 August 2021. NOTE. URL: https://www.w3.org/TR/charmod-norm/COOKIES A. Barth. HTTP State Management Mechanism. April 2011. Proposed Standard. URL: https://httpwg.org/specs/rfc6265.htmlWEBSTORAGE Ian Hickson. Web Storage (Second Edition). 28 January 2021. REC. URL: https://www.w3.org/TR/webstorage/

IDL Index

Exposed=(Window,Worker) interfaceIDBRequest : EventTarget { readonlyattributeanyresult; readonlyattributeDOMException? error; readonlyattribute (IDBObjectStoreorIDBIndexorIDBCursor)? source; readonlyattributeIDBTransaction? transaction; readonlyattributeIDBRequestReadyStatereadyState; // Event handlers: attributeEventHandleronsuccess; attributeEventHandleronerror; }; enumIDBRequestReadyState { “pending”, “done” }; Exposed=(Window,Worker) interfaceIDBOpenDBRequest : IDBRequest { // Event handlers: attributeEventHandleronblocked; attributeEventHandleronupgradeneeded; }; Exposed=(Window,Worker) interfaceIDBVersionChangeEvent : Event { constructor(DOMStringtype, optionalIDBVersionChangeEventIniteventInitDict = {}); readonlyattributeunsignedlonglongoldVersion; readonlyattributeunsignedlonglong? newVersion; }; dictionaryIDBVersionChangeEventInit : EventInit { unsignedlonglongoldVersion = 0; unsignedlonglong? newVersion = null; }; partialinterfacemixinWindowOrWorkerGlobalScope { SameObject readonlyattributeIDBFactoryindexedDB; }; Exposed=(Window,Worker) interfaceIDBFactory { NewObject IDBOpenDBRequestopen(DOMStringname, optional EnforceRange unsignedlonglongversion); NewObject IDBOpenDBRequestdeleteDatabase(DOMStringname); Promise<sequence<IDBDatabaseInfo>> databases(); shortcmp(anyfirst, anysecond); }; dictionaryIDBDatabaseInfo { DOMStringname; unsignedlonglongversion; }; Exposed=(Window,Worker) interfaceIDBDatabase : EventTarget { readonlyattributeDOMStringname; readonlyattributeunsignedlonglongversion; readonlyattributeDOMStringListobjectStoreNames; NewObject IDBTransactiontransaction((DOMStringorsequence<DOMString>) storeNames, optionalIDBTransactionModemode = “readonly”, optionalIDBTransactionOptionsoptions = {}); undefinedclose(); NewObject IDBObjectStorecreateObjectStore( DOMStringname, optionalIDBObjectStoreParametersoptions = {}); undefineddeleteObjectStore(DOMStringname); // Event handlers: attributeEventHandleronabort; attributeEventHandleronclose; attributeEventHandleronerror; attributeEventHandleronversionchange; }; enumIDBTransactionDurability { “default”, “strict”, “relaxed” }; dictionaryIDBTransactionOptions { IDBTransactionDurabilitydurability = “default”; }; dictionaryIDBObjectStoreParameters { (DOMStringorsequence<DOMString>)? keyPath = null; booleanautoIncrement = false; }; Exposed=(Window,Worker) interfaceIDBObjectStore { attributeDOMStringname; readonlyattributeanykeyPath; readonlyattributeDOMStringListindexNames; SameObject readonlyattributeIDBTransactiontransaction; readonlyattributebooleanautoIncrement; NewObject IDBRequestput(anyvalue, optionalanykey); NewObject IDBRequestadd(anyvalue, optionalanykey); NewObject IDBRequestdelete(anyquery); NewObject IDBRequestclear(); NewObject IDBRequestget(anyquery); NewObject IDBRequestgetKey(anyquery); NewObject IDBRequestgetAll(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestgetAllKeys(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestcount(optionalanyquery); NewObject IDBRequestopenCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); NewObject IDBRequestopenKeyCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); IDBIndexindex(DOMStringname); NewObject IDBIndexcreateIndex(DOMStringname, (DOMStringorsequence<DOMString>) keyPath, optionalIDBIndexParametersoptions = {}); undefineddeleteIndex(DOMStringname); }; dictionaryIDBIndexParameters { booleanunique = false; booleanmultiEntry = false; }; Exposed=(Window,Worker) interfaceIDBIndex { attributeDOMStringname; SameObject readonlyattributeIDBObjectStoreobjectStore; readonlyattributeanykeyPath; readonlyattributebooleanmultiEntry; readonlyattributebooleanunique; NewObject IDBRequestget(anyquery); NewObject IDBRequestgetKey(anyquery); NewObject IDBRequestgetAll(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestgetAllKeys(optionalanyquery, optional EnforceRange unsignedlongcount); NewObject IDBRequestcount(optionalanyquery); NewObject IDBRequestopenCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); NewObject IDBRequestopenKeyCursor(optionalanyquery, optionalIDBCursorDirectiondirection = “next”); }; Exposed=(Window,Worker) interfaceIDBKeyRange { readonlyattributeanylower; readonlyattributeanyupper; readonlyattributebooleanlowerOpen; readonlyattributebooleanupperOpen; // Static construction methods: NewObject staticIDBKeyRangeonly(anyvalue); NewObject staticIDBKeyRangelowerBound(anylower, optionalbooleanopen = false); NewObject staticIDBKeyRangeupperBound(anyupper, optionalbooleanopen = false); NewObject staticIDBKeyRangebound(anylower, anyupper, optionalbooleanlowerOpen = false, optionalbooleanupperOpen = false); booleanincludes(anykey); }; Exposed=(Window,Worker) interfaceIDBCursor { readonlyattribute (IDBObjectStoreorIDBIndex) source; readonlyattributeIDBCursorDirectiondirection; readonlyattributeanykey; readonlyattributeanyprimaryKey; SameObject readonlyattributeIDBRequestrequest; undefinedadvance(EnforceRange unsignedlongcount); undefinedcontinue(optionalanykey); undefinedcontinuePrimaryKey(anykey, anyprimaryKey); NewObject IDBRequestupdate(anyvalue); NewObject IDBRequestdelete(); }; enumIDBCursorDirection { “next”, “nextunique”, “prev”, “prevunique” }; Exposed=(Window,Worker) interfaceIDBCursorWithValue : IDBCursor { readonlyattributeanyvalue; }; Exposed=(Window,Worker) interfaceIDBTransaction : EventTarget { readonlyattributeDOMStringListobjectStoreNames; readonlyattributeIDBTransactionModemode; readonlyattributeIDBTransactionDurabilitydurability; SameObject readonlyattributeIDBDatabasedb; readonlyattributeDOMException? error; IDBObjectStoreobjectStore(DOMStringname); undefinedcommit(); undefinedabort(); // Event handlers: attributeEventHandleronabort; attributeEventHandleroncomplete; attributeEventHandleronerror; }; enumIDBTransactionMode { “readonly”, “readwrite”, “versionchange” }; ✔MDNIDBCursor/advance

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/continue

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/continuePrimaryKey

In all current engines.

Firefox10+Safari10.1+Chrome58+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android51+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/delete

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/direction

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/key

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/primaryKey

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/request

In all current engines.

Firefox77+Safari15+Chrome76+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/source

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor/update

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursor

In all current engines.

Firefox16+Safari8+Chrome24+Opera44+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile43+✔MDNIDBCursorWithValue/value

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBCursorWithValue

In all current engines.

Firefox16+Safari8+Chrome24+Opera15+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBDatabase/close

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase/close_event

In all current engines.

Firefox50+Safari10.1+Chrome30+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile?✔MDNIDBDatabase/close_event

In all current engines.

Firefox50+Safari10.1+Chrome30+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView37+Samsung Internet?Opera Mobile?✔MDNIDBDatabase/createObjectStore

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase/deleteObjectStore

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase/name

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase/objectStoreNames

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase/transaction

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase/version

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase/versionchange_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase/versionchange_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBDatabase

In all current engines.

Firefox16+Safari8+Chrome24+Opera15+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBFactory/cmp

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?MDNIDBFactory/databases

FirefoxNoneSafari14+Chrome72+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBFactory/deleteDatabase

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBFactory/open

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBFactory

In all current engines.

Firefox16+Safari8+Chrome24+Opera15+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBIndex/count

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/get

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/getAll

In all current engines.

Firefox44+Safari10.1+Chrome48+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/getAllKeys

In all current engines.

Firefox44+Safari10.1+Chrome48+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/getKey

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/keyPath

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/multiEntry

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/name

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/objectStore

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/openCursor

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/openKeyCursor

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex/unique

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBIndex

In all current engines.

Firefox16+Safari8+Chrome24+Opera15+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBKeyRange/bound_static

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange/includes

In all current engines.

Firefox47+Safari10.1+Chrome52+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange/lower

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange/lowerBound_static

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange/lowerOpen

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange/only_static

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange/upper

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange/upperBound_static

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange/upperOpen

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBKeyRange

In all current engines.

Firefox16+Safari8+Chrome24+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBObjectStore/add

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/autoIncrement

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)?IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/clear

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/count

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/createIndex

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/delete

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/deleteIndex

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/get

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/getAll

In all current engines.

Firefox44+Safari10.1+Chrome48+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android48+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/getAllKeys

In all current engines.

Firefox44+Safari10.1+Chrome48+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android48+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/getKey

In all current engines.

Firefox51+Safari10.1+Chrome48+Opera45+Edge79+Edge (Legacy)?IENoneFirefox for Android58+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile43+✔MDNIDBObjectStore/index

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/indexNames

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/keyPath

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/name

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/openCursor

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/openKeyCursor

In all current engines.

Firefox44+Safari10.1+Chrome23+Opera?Edge79+Edge (Legacy)?IE10+Firefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/put

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore/transaction

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBObjectStore

In all current engines.

Firefox16+Safari8+Chrome24+Opera15+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBOpenDBRequest/blocked_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBOpenDBRequest/upgradeneeded_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBOpenDBRequest

In all current engines.

Firefox16+Safari8+Chrome24+Opera15+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBRequest/error

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBRequest/error_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?IDBTransaction/error_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBRequest/readyState

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBRequest/result

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBRequest/source

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBRequest/success_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBRequest/transaction

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBRequest

In all current engines.

Firefox16+Safari8+Chrome24+Opera15+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android25+Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBTransaction/abort

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction/abort_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction/commit

In all current engines.

Firefox74+Safari15+Chrome76+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction/complete_event

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction/db

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?MDNIDBTransaction/durability

FirefoxNoneSafari15+Chrome83+Opera70+Edge83+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction/error

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction/mode

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction/objectStore

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction/objectStoreNames

In all current engines.

Firefox10+Safari10.1+Chrome48+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBTransaction

In all current engines.

Firefox16+Safari8+Chrome24+Opera15+Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile14+✔MDNIDBVersionChangeEvent/IDBVersionChangeEvent

In all current engines.

Firefox25+Safari10+Chrome41+Opera?Edge79+Edge (Legacy)?IENoneFirefox for Android?iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBVersionChangeEvent/newVersion

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBVersionChangeEvent/oldVersion

In all current engines.

Firefox10+Safari8+Chrome23+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?✔MDNIDBVersionChangeEvent

In all current engines.

Firefox16+Safari8+Chrome24+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView4.4+Samsung Internet?Opera Mobile?✔MDNindexedDB

In all current engines.

Firefox16+Safari8+Chrome24+Opera?Edge79+Edge (Legacy)12+IE10+Firefox for Android22+iOS Safari?Chrome for Android?Android WebView?Samsung Internet?Opera Mobile?

FAQ

Apakah WPT Global memiliki aplikasi seluler?

WPT Global tersedia untuk dimainkan di komputer Anda dalam versi Windows dan Mac, serta di perangkat seluler Anda, baik Android maupun iOS . Langkah-langkah untuk mulai menikmati pengalaman Anda di WPT Global sederhana dan intuitif.

Apakah WPT Global memiliki permainan uang tunai?

WPT Global is available to play on your computer in both Windows and Mac versions, as well as on your mobile device, whether it’s Android or iOS. The steps to start enjoying your experience on WPT Global are simple and intuitive.

Bagaimana cara menginstal WPT Global?

Unduh Perangkat Lunak WPT Global Anda Ikuti tautan PokerNews untuk mengunduh perangkat lunak WPT Global Anda, baik di komputer Windows atau Mac atau di perangkat seluler Android atau iOS Anda . Instal Aplikasi di Perangkat Anda Setelah perangkat lunak diunduh, lanjutkan penginstalan dengan menjalankan berkas penginstal.

Di mana Anda bisa bermain WPT Global?

Download Your WPT Global Software Follow the PokerNews link to download your WPT Global software, either on a Windows or Mac computer or on your Android or iOS mobile device. Install the Application on Your Device Once the software is downloaded, proceed with the installation by running the installer file.

¿Puedes jugar WPT Global en el ordenador?

ClubWPT™ ofrece juegos de póquer gratuitos y con sorteos . Los torneos con sorteos disponibles en ClubWPT otorgan más de $200,000 en efectivo y premios cada mes, incluidos más de 350 asientos para eventos en vivo del Campeonato WPT.

¿WPT Global tiene una aplicación móvil?

Aplicación móvil WPT Global: características, disponibilidad y cómo descargarla WPT Global, una de las plataformas de póquer en línea de más rápido crecimiento, ofrece una aplicación móvil cómoda y fácil de usar para dispositivos iOS y Android. Este artículo lo guiará a través de las funciones, la disponibilidad y el proceso de descarga de la aplicación. Disponibilidad y compatibilidad La aplicación móvil WPT Global está disponible para: 1. Dispositivos iOS (iPhone y iPad) con iOS 13.

Apakah WPT Global memiliki aplikasi seluler?

WPT Global tersedia untuk dimainkan di komputer Anda dalam versi Windows dan Mac, serta di perangkat seluler Anda, baik Android maupun iOS . Langkah-langkah untuk mulai menikmati pengalaman Anda di WPT Global sederhana dan intuitif.

¿El WPT Poker es gratuito?

El World Poker Tour (WPT) es una serie de torneos de póker internacionales con la mayoría de los jugadores profesionales del mundo.

Apakah WPT Global memiliki permainan uang tunai?

WPT Global is available to play on your computer in both Windows and Mac versions, as well as on your mobile device, whether it’s Android or iOS. The steps to start enjoying your experience on WPT Global are simple and intuitive.

Este sitio solo recopila artículos relacionados. Para ver el original, copia y abre el siguiente enlace:Indexed Database API 3.0

🔥 💋 Descargar WPT 🎧
💋 Últimos Artículos 🎀 🎳 Artículos Populares 🎈
🎤 Artículos Recomendados 🎯
# Título del Artículo Palabra clave Enlace del Artículo Detalles del Artículo

🎵 Descarga e Instala la Aplicación WPT Global wpt mexico WPT Global México Descarga e Instala WPTGlobal Sigue estos pasos para descargar nuestro software de póker e instalar la aplicación WPT Global. Paso 1: Descarga la Aplicación WPTGlobal Selecciona el botón “Descargar Ahora” para iniciar la descarga. Una vez que la aplicación se haya descargado en tu computadora abre el archivo (revisa tu carpeta de “Descargas”). Paso 2: Instala la Aplicación WPTGlobal Una vez que la aplicación WPT Global se haya descargado en tu computadora abre el archivo (revisa tu carpeta de ‘Descargas’). 🎻 Descarga e Instala WPTGlobal Sigue estos pasos para descargar nuestro software de póker e instalar la aplicación WPT Global. Paso 1: Descarga la Aplicación WPTGlobal Selecciona el botón “Descargar Ahora” para iniciar la descarga. Una vez que la aplicación se haya descargado en tu computadora abre el archivo (revisa tu carpeta de “Descargas”). Paso 2: Instala la Aplicación WPTGlobal Una vez que la aplicación WPT Global se haya descargado en tu computadora abre el archivo (revisa tu carpeta de ‘Descargas’).

Descarga e Instala WPTGlobal Sigue estos pasos para descargar nuestro software de póker e instalar la aplicación WPT Global. Paso 1: Descarga la Aplicación WPTGlobal Selecciona el botón “Descargar Ahora” para iniciar la descarga. Una vez que la aplicación se haya descargado en tu computadora, abre el archivo (revisa tu carpeta de “Descargas”). Paso 2: Instala la Aplicación WPTGlobal Una vez que la aplicación WPT Global se haya descargado en tu computadora, abre el archivo (revisa tu carpeta de ‘Descargas’).

11/20
WPT Global H5