Quick start
Run two-browser collaboration, then move the minimal Client, Transport, Endpoint, Service, and Adapter composition into your application.
This page describes two paths. The first runs the official example and verifies the complete collaboration path in two browsers. The second presents the minimal Server and Web assembly, which you can copy into your own Univer application.
Before starting, complete the environment and version requirements. Every @univerjs/* and @univerjs-pro/* package must be pinned to the same matching release cohort.
Path one: run the official example
Before running the example
This repository requires Node.js 24+ and declares pnpm 10.32.1. Check node --version and pnpm --version, use the repository lockfile, and run all pnpm example:* commands from the repository root. Each command builds the browser and the server, type-checks the example, and then starts it. These commands do not provide a hot-reload development server, so after editing source files you must stop the process and run the command again.
If you have a License, set UNIVER_LICENSE and UNIVER_LICENSE_KEY in your shell before running the command. The build embeds UNIVER_LICENSE into the browser bundle through vite.config.ts, and the Collaboration SDK reads both variables when the server starts. Rerun the command after changing the License. See License.
git clone https://github.com/dream-num/univer-collaboration-examples.gitcd univer-collaboration-examplespnpm install --frozen-lockfilepnpm example:quick-startOpen the following URL:
http://127.0.0.1:3010/?unit=quick-start-sheetVerify realtime collaboration
- Open the complete URL in one browser window.
- Open the same URL in a second window or tab.
- Change one cell in either Sheet.
- Confirm that the same edit appears in the other browser.
Each window opens its own WebSocket session. When you later run the permissions example, use separate browser profiles to keep the two accounts’ login cookies independent.
What success proves
Univer Collaboration Client → Node Transport → UniverCollabEndpoint → UniverCollabService → MemoryDatabaseAdapterIf the two browsers remain synchronized, the complete path works. Each browser loaded a Unit over HTTP, opened a WebSocket Session with a one-time Session Ticket, and joined the same Room. The Service performed OT, confirmed a new revision, saved it through the Adapter, and the Endpoint broadcast that revision to the other members.
Path two: move it into your application
The code below is the minimal Server and Web assembly. The official Quick Start contains the complete application structure:
If you already have a Univer Web application, keep its Runtime, presets, and UI, and add only the Collaboration Client configuration and the Server described below. For an empty project, copy index.html, vite.config.ts, and the styles from the Quick Start directory and use them as the application shell.
Read and migrate the runnable files
Copy examples/quick-start as the initial skeleton and retain package.json, index.html, vite.config.ts, web/styles.css, web/main.ts, and server/main.ts. Run its build and start scripts from that directory, because Express serves dist/web relative to the working directory. Keep the Vite license definition, and give #app a nonzero height. The code below only explains how these parts are assembled; for a complete runnable project, use the repository files.
The example serves the page and /universer-api from the same origin. If you move the frontend elsewhere, proxy both HTTP and the WebSocket upgrade to the backend, or change all five client URLs together. unit must match the ID that the backend created; a URL parameter alone does not create a document. The example reads unit and loads the document explicitly with loadSheetAsync(). In your application, set the current user before loading, as described in Collaboration integration.
1. Install one matching package cohort
The Server needs Transport, Endpoint, Service, and one Database Adapter. The browser needs the Collaboration Client. Install the packages, then pin every Univer package to the same exact version:
pnpm add \ @univerjs-pro/collaboration \ @univerjs-pro/collaboration-client \ @univerjs-pro/collaboration-client-ui \ @univerjs-pro/collaboration-database-memory \ @univerjs-pro/collaboration-endpoint \ @univerjs-pro/collaboration-service \ @univerjs-pro/collaboration-transport-node \ @univerjs-pro/license \ @univerjs/core \ @univerjs/preset-sheets-core \ @univerjs/presets \ @univerjs/protocol \ express react react-dom rxjsThe official example manifest is the runnable, authoritative reference for the current package composition and exact versions.
2. Create the service, endpoint, and initial Unit
UniverCollabService is the authoritative collaboration core. The Endpoint maps the browser protocol onto the Service, and the Memory Adapter temporarily stores snapshots, changesets, and revisions:
import type { IWorkbookData } from "@univerjs/core";import { createServer } from "node:http";import express from "express";import { LocaleType } from "@univerjs/core";import { MemoryDatabaseAdapter } from "@univerjs-pro/collaboration-database-memory";import { UniverCollabEndpoint } from "@univerjs-pro/collaboration-endpoint";import { UniverCollabService } from "@univerjs-pro/collaboration-service";import { createNodeTransport } from "@univerjs-pro/collaboration-transport-node";import { ErrorCode, UniverType } from "@univerjs/protocol";const UNIT_ID = "quick-start-sheet";const unitData: IWorkbookData = { id: UNIT_ID, rev: 1, name: "Quick Start Sheet", appVersion: "", locale: LocaleType.EN_US, sheetOrder: ["sheet-1"], sheets: { "sheet-1": { id: "sheet-1", name: "Sheet 1", rowCount: 100, columnCount: 26, cellData: {}, }, }, styles: {}, resources: [],};const database = new MemoryDatabaseAdapter();const service = new UniverCollabService({ dbAdapter: database });const endpoint = new UniverCollabEndpoint(service);const transport = createNodeTransport();transport.use(async (context, next) => { context.userID = "demo-user"; await next();});transport.register(endpoint);await service.createUnitFromData( { type: UniverType.UNIVER_SHEET, data: unitData }, { userID: "demo-user" },);The fixed demo-user illustrates how a trusted identity flows from the Transport into the Endpoint and the Service. A production application validates its own cookie, bearer token, or session inside transport.use(), and then sets a stable business userID.
3. Mount authorization, HTTP, and WebSocket entry points
The current Collaboration Client queries an authorization protocol. Quick Start returns allowed: true for that route on every request and attaches the Transport to the application's HTTP server:
const app = express();app.post("/universer-api/authz/-/object/-/batch_allowed", express.json(), (request, response) => { const body = request.body as { requests: Array<{ unitID: string; objectID: string; actions: unknown[] }>; }; response.json({ error: { code: ErrorCode.OK, message: "" }, objectActions: body.requests.map((item) => ({ unitID: item.unitID, objectID: item.objectID, actions: item.actions.map((action) => ({ action, allowed: true })), })), });});app.use(express.static("dist/web"));const server = createServer(app);transport.attach(server);server.listen(3010, "127.0.0.1");Granting every request is a teaching shortcut, not a security boundary. A production application must protect HTTP reads, realtime JOIN, changeset submission, and Unit lifecycle operations. See Identity and authorization for the complete coverage model.
4. Register the collaboration client in browser Runtime
Retain the standard Web SDK and presets, then add the Collaboration plugins and the protocol URLs:
Plugin configuration
UniverLicensePlugin
licensestringContents of the client license file.
UniverCollaborationClientPlugin
socketServiceCtor<ICollaborationSocketService>Socket implementation the current runtime uses.sendChangesetTimeoutnumberDefault:2000How long edits are batched, in milliseconds, before they are sent.authzUrlstringDefault:'/universer-api/authz'Endpoint for permission checks.snapshotServerUrlstringDefault:'/universer-api/snapshot'Endpoint for loading document snapshots.collabSubmitChangesetUrlstringDefault:'/universer-api/comb'Endpoint for submitting changesets.collabWebSocketUrlstringDefault:'ws://127.0.0.1:8000/universer-api/comb/connect'WebSocket endpoint for realtime changes.wsSessionTicketUrlstringDefault:'/universer-api/user/session-ticket'Endpoint for obtaining a WebSocket session ticket.
Preset configuration
UniverSheetsCorePreset
containerstring | HTMLElementDefault:'app'Element to mount into, or its DOM ID.
import { LocaleType, LogLevel } from "@univerjs/core";import { UniverCollaborationPlugin } from "@univerjs-pro/collaboration";import { UniverCollaborationClientPlugin } from "@univerjs-pro/collaboration-client";import CollaborationClientEnUS from "@univerjs-pro/collaboration-client/locale/en-US";import { BrowserCollaborationSocketService, UniverCollaborationClientUIPlugin,} from "@univerjs-pro/collaboration-client-ui";import CollaborationClientUIEnUS from "@univerjs-pro/collaboration-client-ui/locale/en-US";import { UniverLicensePlugin } from "@univerjs-pro/license";import { UniverSheetsCorePreset } from "@univerjs/preset-sheets-core";import UniverPresetSheetsCoreEnUS from "@univerjs/preset-sheets-core/locales/en-US";import { createUniver, defaultTheme, mergeLocales } from "@univerjs/presets";import "@univerjs-pro/collaboration-client/facade";import "@univerjs/preset-sheets-core/lib/index.css";import "@univerjs-pro/collaboration-client-ui/lib/index.css";const httpProtocol = location.protocol === "https:" ? "https" : "http";const wsProtocol = location.protocol === "https:" ? "wss" : "ws";const baseURL = `${httpProtocol}://${location.host}/universer-api`;const unitId = new URLSearchParams(location.search).get("unit");if (!unitId) throw new Error("Open the URL printed by the server; it names the Sheet with ?unit=.");const { univerAPI } = createUniver({ locale: LocaleType.EN_US, locales: { [LocaleType.EN_US]: mergeLocales( UniverPresetSheetsCoreEnUS, CollaborationClientEnUS, CollaborationClientUIEnUS, ), }, theme: defaultTheme, logLevel: LogLevel.WARN, collaboration: true, presets: [UniverSheetsCorePreset({ container: "app" })], plugins: [ [UniverLicensePlugin, { license: import.meta.env.UNIVER_LICENSE || undefined }], UniverCollaborationPlugin, [ UniverCollaborationClientPlugin, { socketService: BrowserCollaborationSocketService, sendChangesetTimeout: 200, authzUrl: `${baseURL}/authz`, snapshotServerUrl: `${baseURL}/snapshot`, collabSubmitChangesetUrl: `${baseURL}/comb`, collabWebSocketUrl: `${wsProtocol}://${location.host}/universer-api/comb/connect`, wsSessionTicketUrl: `${baseURL}/user/session-ticket`, }, ], UniverCollaborationClientUIPlugin, ],});const workbook = await univerAPI.getCollaboration().loadSheetAsync(unitId);if (!workbook) throw new Error("Document could not be loaded");The page requires an element with id="app" and selects the Unit through query parameters:
/?unit=quick-start-sheet5. Replace teaching configuration with application capabilities
| Teaching configuration | Replace it with |
|---|---|
A fixed demo-user | Application authentication Middleware and a stable user ID |
| Permission checks that always allow | Server ACL covering read, JOIN, submit, and lifecycle operations |
| A fixed Unit | Application create API and product record calling createUnitFromData() |
| The Memory Adapter | SQLite or a contract-tested custom persistent Adapter |
Continue with Database Adapters and Identity and authorization. Then add History, Thread Comment, Worktree, or Exchange as required. The examples index covers every runnable composition.
If the first run fails
| Symptom | Check |
|---|---|
| Install or build fails | Node.js 24+, the declared pnpm version, and matching Univer package versions |
| Port 3010 is occupied | Stop the previous example, or run with PORT=3011 and use that port in both browser URLs |
| Empty page or missing assets | Build completed; start runs from the example directory; #app has height |
| Page opens but edits do not sync | The same complete URL in both windows; successful snapshot and session-ticket requests; a WebSocket connection at /universer-api/comb/connect |
| Data disappears after restart | Quick Start uses memory; continue with the SQLite example |
How is this guide?