benweet/stackedit · critical · Error
Can't connect to IndexedDB.
Error message
Can't connect to IndexedDB.
What it means
The IndexedDB open request failed inside the localDbSvc constructor for a workspace database (src/services/localDbSvc.js:27). The error handler on `indexedDB.open(this.dbName, dbVersion)` rethrows as this error, meaning the database connection could not be established. Common causes are storage access being blocked by the browser, a corrupt database, or a version-change conflict where another tab holds an older version open and blocks the upgrade.
Source
Thrown at src/services/localDbSvc.js:27
const dbStoreName = 'objects';
const { silent } = utils.queryParams;
const resetApp = localStorage.getItem('resetStackEdit');
if (resetApp) {
localStorage.removeItem('resetStackEdit');
}
class Connection {
constructor(workspaceId = store.getters['workspace/currentWorkspace'].id) {
this.getTxCbs = [];
// Make the DB name
this.dbName = utils.getDbName(workspaceId);
// Init connection
const request = indexedDB.open(this.dbName, dbVersion);
request.onerror = () => {
throw new Error("Can't connect to IndexedDB.");
};
request.onsuccess = (event) => {
this.db = event.target.result;
this.db.onversionchange = () => window.location.reload();
this.getTxCbs.forEach(({ onTx, onError }) => this.createTx(onTx, onError));
this.getTxCbs = null;
};
request.onupgradeneeded = (event) => {
const eventDb = event.target.result;
const oldVersion = event.oldVersion || 0;
// We don't use 'break' in this switch statement,
// the fall-through behavior is what we want.
/* eslint-disable no-fallthrough */
switch (oldVersion) {View on GitHub (pinned to 6dce2a5e36)
Solutions
- Allow site data/cookies for the app's origin in browser settings.
- Close other tabs of the app and reload so a pending version upgrade can complete.
- Clear the site's storage for this origin to remove a corrupt database, then reload.
- Retry the connection after a transient failure; log request.error for the concrete DOMException.
Example fix
// before
request.onerror = () => {
throw new Error("Can't connect to IndexedDB.");
};
// after
request.onerror = () => {
console.error('IndexedDB open failed:', request.error);
throw new Error(`Can't connect to IndexedDB. (${request.error && request.error.name})`);
}; Defensive patterns
Strategy: retry
Validate before calling
function canUseIndexedDB() {
try {
return !!window.indexedDB && typeof indexedDB.open === 'function';
} catch (e) {
return false; // storage access denied (e.g. blocked cookies)
}
} Type guard
function isOpenError(err) {
return err && ['UnknownError', 'SecurityError', 'InvalidStateError', 'VersionError'].includes(err.name);
} Try / catch
try {
await connectDb();
} catch (err) {
if (isOpenError(err) && retries < 3) {
await delay(500 * (retries + 1));
return connectDbWithRetry(retries + 1);
}
showStorageErrorDialog(err);
} Prevention
- Retry DB open with backoff on transient errors; surface request.error details.
- Handle onversionchange by closing the connection so upgrades are not blocked.
- Advise users not to block all site data/cookies for the app origin.
- Wrap indexedDB.open in a promise and log the DOMException name for diagnosis.
When it happens
Trigger: `indexedDB.open(dbName, dbVersion)` fires its onerror handler: storage quota/blocked cookies settings, a corrupted or deleted database file, blocked version upgrade (an open connection in another context at a lower version without onversionchange handling), or storage disabled entirely.
Common situations: Browser set to 'block all cookies'/site data; corrupted profile storage after a browser crash; having the app open in an old tab while a new deploy bumped dbVersion; iOS Safari low-storage eviction.
Related errors
AI-assisted analysis of benweet/stackedit@6dce2a5e36 (2026-09-01).
Data as JSON: /api/errors/135b9de6ad27d270.
Report an issue: GitHub.