# Recovery API

> The recovery store API: createIndexedDbRecovery, createMemoryRecovery and the RecoveryStore interface, including setNow for the moment a page closes.

Source: https://fabricjs-document-engine.jscrate.dev/docs/api/recovery-api
Last updated: 2026-09-28

The recovery store API decides where copies of unsaved work are kept. Pass a store to the `recovery` option of `createDocumentEngine`. How recovery behaves is explained in the [recovery guide](https://fabricjs-document-engine.jscrate.dev/docs/guides/recovery).

## Built-in stores

```ts
function createIndexedDbRecovery(options?: IndexedDbRecoveryOptions): RecoveryStore
```

IndexedDB copies while the user edits, plus a synchronous localStorage copy when the page closes.

```ts
function createMemoryRecovery(): RecoveryStore
```

An in-memory recovery store for tests.

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `databaseName` | `string` | — | The IndexedDB database name. |
| `storeName` | `string` | — | The object store name. |

## The RecoveryStore interface

Implement this recovery store API to keep copies somewhere else:

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `get` (required) | `(key: string): Promise<unknown>` | — | Reads a copy. |
| `set` (required) | `(key: string, value: unknown): Promise<void>` | — | Writes a copy. |
| `setNow` | `(key: string, value: unknown): void` | — | Writes a copy synchronously, for the moment the page closes. |
| `delete` (required) | `(key: string): Promise<void>` | — | Deletes a copy. |
| `keys` (required) | `(): Promise<string[]>` | — | Lists the stored keys. |

`setNow` is optional. Browsers do not wait for async writes while a page closes, so the engine calls `setNow` at that moment if it exists. `createIndexedDbRecovery` uses localStorage for it.

## The option

| Name | Type | Default | Description |
| --- | --- | --- | --- |
| `store` (required) | `RecoveryStore` | — | Where copies are kept, such as `createIndexedDbRecovery()`. |
| `interval` | `number` | `2000` | Write a copy at most once every this many milliseconds while there are unsaved changes. |

The engine methods that use the recovery store API, such as `getRecoverableDocuments` and `restoreRecovery`, are listed on [DocumentEngine](https://fabricjs-document-engine.jscrate.dev/docs/api/document-engine).
