> ## Documentation Index
> Fetch the complete documentation index at: https://docs.mirage.strukto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# OPFS

> Persistent in-browser filesystem backed by the Origin Private File System.

`OPFSResource` mounts the [Origin Private File System](https://web.dev/articles/origin-private-file-system) as a Mirage resource. Files persist across page reloads but stay scoped to the current origin.

<Note>
  Browser only. There is no OPFS in Node; for local persistence in Node, use [Disk](/typescript/setup/disk).
</Note>

## Install

```bash theme={null}
pnpm add @struktoai/mirage-browser
```

## Config

```ts theme={null}
import { MountMode, OPFSResource, Workspace } from '@struktoai/mirage-browser'

const opfs = new OPFSResource({ root: 'mirage' })

const ws = new Workspace({ '/data': opfs }, { mode: MountMode.WRITE })
await ws.execute('echo persistent | tee /data/note.txt')
```

| Field  | Default | Notes                                                                      |
| ------ | ------- | -------------------------------------------------------------------------- |
| `root` | `''`    | Subdirectory under the OPFS root. Useful to namespace multiple workspaces. |

## Mount mode

`read`, `write`, `exec`.

## Storage and quotas

The browser sets per-origin quotas (typically a fraction of free disk, single-digit GB on most setups). Hitting it raises `QuotaExceededError`.

```ts theme={null}
const { quota, usage } = await navigator.storage.estimate()
console.log(`${usage} / ${quota} bytes`)
```

For long-lived workspaces, request persistent storage early so the browser doesn't evict your data under storage pressure:

```ts theme={null}
await navigator.storage.persist()
```

See [TypeScript Limitations: Browser](/typescript/limitations#browser) for the full set of browser constraints.
