WebAssembly engine
The @surrealdb/wasm package is a plugin for the JavaScript SDK that allows you to run SurrealDB as an embedded database within a browser environment. It supports in-memory databases and persistent storage via IndexedDB, and can optionally run inside a Web Worker to keep the main thread responsive.
Important
Installing the WASM engine
Before installing the WASM engine, you need the core JavaScript SDK installed. Then add the @surrealdb/wasm package.
Registering the engine
Import createWasmEngines from @surrealdb/wasm and spread it into the engines option alongside createRemoteEngines from the core SDK. This registers the embedded protocols while keeping remote connections available.
Supported connection protocols
Once the WASM engine is registered, you can connect to SurrealDB using the embedded protocols.
| Protocol | Description |
|---|---|
mem:// | In-memory database (data is lost when the page reloads) |
indxdb:// | Persistent database backed by IndexedDB |
Remote protocols (ws://, wss://, http://, https://) remain available when createRemoteEngines() is also registered.
Running in a Web Worker
The WASM engine can run inside a Web Worker to offload database operations from the main thread. This keeps your interface responsive during computationally intensive queries.
Configuring your bundler
If you are using a bundler like Vite, you may need to exclude the WASM package from dependency optimization and enable top-level await.
Learn more
WebAssembly engine reference for additional engine configuration
Connecting to SurrealDB for connection options and reconnection behavior