This feature is well established and works across many devices and browser versions. It’s been available across browsers since September 2021.
Note: This feature is available in Web Workers.
The open() method of the IDBFactory interface requests opening a connection to a database.
The method returns an IDBOpenDBRequest object immediately, and performs the open operation asynchronously. If the operation is successful, a success event is fired on the request object that is returned from this method, with its result attribute set to the new IDBDatabase object for the connection.
May trigger upgradeneeded, blocked or versionchange events.
open(name) open(name, version)
nameThe name of the database.
version OptionalOptional. The version to open the database with. If the version is not provided and the database exists, then a connection to the database will be opened without changing its version. If the version is not provided and the database does not exist, then it will be created with version 1.
A IDBOpenDBRequest object on which subsequent events related to this request are fired.
If the operation is successful, the value of the request's result property is a IDBDatabase object representing the connection to the database.
TypeErrorThrown if the value of version is not a number greater than zero.
Example of calling open with the current specification's version parameter:
const request = window.indexedDB.open("toDoList", 4);
In the following code snippet, we make a request to open a database, and include handlers for the success and error cases. For a full working example, see our To-do Notifications app (View the example live).
const note = document.querySelector("ul");
// Let us open version 4 of our database
const DBOpenRequest = window.indexedDB.open("toDoList", 4);
// these two event handlers act on the database being opened
// successfully, or not
DBOpenRequest.onerror = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Error loading database.";
};
DBOpenRequest.onsuccess = (event) => {
note.appendChild(document.createElement("li")).textContent =
"Database initialized.";
// store the result of opening the database in the db
// variable. This is used a lot later on, for opening
// transactions and suchlike.
db = DBOpenRequest.result;
};
| Specification |
|---|
| Indexed Database API 3.0> # ref-for-dom-idbfactory-open②> |
| Desktop | Mobile | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Opera | Safari | Chrome Android | Firefox for Android | Opera Android | Safari on IOS | Samsung Internet | WebView Android | WebView on iOS | |
open |
23 | 12 | 10 | 15 | 158–14 | 25 | 22 | 14 | 1514–15In some releases of Safari on iOS 14, the firstindexedDB.open() call hangs forever, see bug 226547. |
1.5 | 4.4 | 1514–15In some releases of WebView on iOS 14, the firstindexedDB.open() call hangs forever, see bug 226547. |
IDBDatabase
IDBTransaction
IDBKeyRange
IDBObjectStore
IDBCursor
© 2005–2025 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/IDBFactory/open