Headless Univer

Headless Univer is Univer's content runtime without an attached editor UI. It uses the same content models, commands, calculation, and Facade APIs as the browser editor. It can run in Node.js to process content, or in a browser for tasks that require no UI. The available capabilities depend on which product and feature plugins are registered.

In Node.js, it can create or load a document, read and edit paragraphs and text, change structure and styles, and save Univer snapshots. Tables, lists, columns, formulas, and shapes require their content plugins. Editing content does not produce page screenshots.

The example below uses plugin mode. @univerjs/core and the product content plugins form the Headless content layer. @univerjs/ui, the product *-ui packages, and the default browser core presets are not part of this setup. The example keeps @univerjs/engine-render as a shared dependency but mounts neither a Canvas nor an editor. For the complete classification and the exceptions, see Headless package boundaries.

Local snapshot operations require no collaboration service. The collaboration example also requires a client, a server, and authentication. Office conversion requires the Server SDK, and screenshots require a rendering runtime. Importing /facade alone registers no feature plugins and does not turn UI APIs into Headless APIs.

Installation

Shell
pnpm add @univerjs/core @univerjs/engine-render @univerjs/engine-formula @univerjs/docs

Usage

TypeScript
import { LocaleType, Univer } from '@univerjs/core'import { FUniver } from '@univerjs/core/facade'import { UniverDocsPlugin } from '@univerjs/docs'import { UniverFormulaEnginePlugin } from '@univerjs/engine-formula'import { UniverRenderEnginePlugin } from '@univerjs/engine-render'import '@univerjs/docs/facade'const univer = new Univer({  locale: LocaleType.EN_US,  locales: {    [LocaleType.EN_US]: {},  },})univer.registerPlugin(UniverRenderEnginePlugin)univer.registerPlugin(UniverFormulaEnginePlugin)univer.registerPlugin(UniverDocsPlugin)const univerAPI = FUniver.newAPI(univer)univerAPI.createDocument({})

Collaborative editing in Node.js

Node.js can act as a collaboration client. It loads an existing document from the server, edits the document through the Facade API, and synchronizes the changes to every other client that has the same document open. Before running the example, prepare a collaboration service, a client license, and an accessible document ID.

Plugin configuration

UniverLicensePlugin

  • license
    string
    Contents of the client license file.

UniverDrawingPlugin

  • override
    [DependencyIdentifier, Provider | null][]
    Dependency overrides the drawing plugin applies.
    • [0]
      DependencyIdentifier
      Identifies the dependency. For image storage, use IImageIoService.
    • [1]
      Provider | null
      The provider that replaces the default one. Pass null to let collaboration supply this service.

UniverCollaborationClientPlugin

  • socketService
    Ctor<ICollaborationSocketService>
    The socket implementation this runtime uses.
  • enableOfflineEditing
    booleanDefault: false
    Allows editing locally while offline.
  • enableSingleActiveInstanceLock
    booleanDefault: false
    Keeps a document actively edited in only one browser instance.
  • snapshotServerUrl
    stringDefault: '/universer-api/snapshot'
    Endpoint that serves document snapshots.
  • collabSubmitChangesetUrl
    stringDefault: '/universer-api/comb'
    Endpoint where changesets are submitted.
  • collabWebSocketUrl
    stringDefault: 'ws://127.0.0.1:8000/universer-api/comb/connect'
    WebSocket endpoint for realtime changes.
  • wsSessionTicketUrl
    stringDefault: '/universer-api/user/session-ticket'
    Endpoint that issues a WebSocket session ticket.
  • uploadFileServerUrl
    stringDefault: '/universer-api/stream/file/upload'
    Endpoint for file uploads.
  • signUrlServerUrl
    stringDefault: '/universer-api/file/{fileID}/sign-url'
    Endpoint that signs file URLs. Keep the {fileID} placeholder.
  • downloadEndpointUrl
    string
    Base URL for file downloads.
  • authzUrl
    stringDefault: '/universer-api/authz'
    Endpoint for permission checks.
  • sendChangesetTimeout
    numberDefault: 2000
    How long edits are batched before they are sent, in milliseconds.
  • retryConnectingInterval
    numberDefault: 20000
    Reconnect interval in milliseconds.
  • customHeaders
    Record<string, string>
    Extra headers sent with the connection.
    • [header]
      string
      The value sent for this HTTP header.

Example files

Arrange the files as follows:

text
src/docs/node/├── main.ts└── univer.ts
  • univer.ts creates Univer and registers the document feature plugins, the Facade extensions, and the Node.js collaboration client.
  • main.ts loads a collaborative document and exercises paragraphs, text, headers and footers, callouts, code blocks, quotes, lists, shapes, tables, and columns.

Replace your-license, the server URL, and the Cookie in univer.ts, and the document ID in main.ts.

TypeScript
import { UniverCollaborationPlugin } from '@univerjs-pro/collaboration'import { UniverCollaborationClientPlugin } from '@univerjs-pro/collaboration-client'import {  NodeCollaborationSocketService,  UniverCollaborationClientNodePlugin,} from '@univerjs-pro/collaboration-client-node'import { UniverDocsCalloutPlugin } from '@univerjs-pro/docs-callout'import { UniverDocsCodePlugin } from '@univerjs-pro/docs-code'import { UniverDocsColumnPlugin } from '@univerjs-pro/docs-column'import { UniverDocsLatexPlugin } from '@univerjs-pro/docs-latex'import { UniverDocsListPlugin } from '@univerjs-pro/docs-list'import { UniverDocsQuotePlugin } from '@univerjs-pro/docs-quote'import { UniverDocsReferencePlugin } from '@univerjs-pro/docs-reference'import { UniverDocsShapePlugin } from '@univerjs-pro/docs-shape'import { UniverDocsTablePlugin } from '@univerjs-pro/docs-table'import { UniverLicensePlugin } from '@univerjs-pro/license'import {  IAuthzIoService,  IImageIoService,  IMentionIOService,  IUndoRedoService,  LocaleType,  Univer,} from '@univerjs/core'import { UniverDocsPlugin } from '@univerjs/docs'import { UniverDocsDrawingPlugin } from '@univerjs/docs-drawing'import { UniverDocsHyperLinkPlugin } from '@univerjs/docs-hyper-link'import { UniverDrawingPlugin } from '@univerjs/drawing'import { UniverRenderEnginePlugin } from '@univerjs/engine-render'import { UniverNetworkPlugin } from '@univerjs/network'import { UniverThreadCommentPlugin } from '@univerjs/thread-comment'import '@univerjs/docs/facade'import '@univerjs/docs-drawing/facade'import '@univerjs-pro/docs-shape/facade'import '@univerjs-pro/docs-callout/facade'import '@univerjs-pro/docs-reference/facade'import '@univerjs-pro/docs-code/facade'import '@univerjs-pro/docs-list/facade'import '@univerjs-pro/docs-quote/facade'import '@univerjs-pro/docs-table/facade'import '@univerjs-pro/docs-column/facade'import '@univerjs-pro/docs-latex/facade'import '@univerjs-pro/collaboration-client/facade'export function createUniverOnNode(): Univer {  const univer = new Univer({    locale: LocaleType.EN_US,    locales: {},    override: [      [IAuthzIoService, null],      [IUndoRedoService, null],      [IMentionIOService, null],    ],  })  univer.registerPlugin(UniverLicensePlugin, {    license: 'your-license',  })  univer.registerPlugin(UniverRenderEnginePlugin)  univer.registerPlugin(UniverThreadCommentPlugin)  univer.registerPlugin(UniverDrawingPlugin, {    override: [[IImageIoService, null]],  })  univer.registerPlugin(UniverDocsPlugin)  univer.registerPlugin(UniverDocsDrawingPlugin)  univer.registerPlugin(UniverDocsHyperLinkPlugin)  univer.registerPlugin(UniverDocsReferencePlugin)  univer.registerPlugin(UniverDocsCalloutPlugin)  univer.registerPlugin(UniverDocsCodePlugin)  univer.registerPlugin(UniverDocsListPlugin)  univer.registerPlugin(UniverDocsQuotePlugin)  univer.registerPlugin(UniverDocsShapePlugin)  univer.registerPlugin(UniverDocsTablePlugin)  univer.registerPlugin(UniverDocsColumnPlugin)  univer.registerPlugin(UniverDocsLatexPlugin)  registerCollaborationPlugins(univer)  return univer}function registerCollaborationPlugins(univer: Univer): void {  const serverUrl = 'https://your-univer-server.example.com'  univer.registerPlugin(UniverNetworkPlugin)  univer.registerPlugin(UniverCollaborationPlugin)  univer.registerPlugin(UniverCollaborationClientPlugin, {    socketService: NodeCollaborationSocketService,    enableOfflineEditing: false,    enableSingleActiveInstanceLock: false,    snapshotServerUrl: `${serverUrl}/universer-api/snapshot`,    collabSubmitChangesetUrl: `${serverUrl}/universer-api/comb`,    collabWebSocketUrl: `${serverUrl}/universer-api/comb/connect`,    wsSessionTicketUrl: `${serverUrl}/universer-api/user/session-ticket`,    uploadFileServerUrl: `${serverUrl}/universer-api/stream/file/upload`,    signUrlServerUrl: `${serverUrl}/universer-api/file/{fileID}/sign-url`,    downloadEndpointUrl: serverUrl,    authzUrl: `${serverUrl}/universer-api/authz`,    sendChangesetTimeout: 200,    retryConnectingInterval: 1000,    customHeaders: {      // Example: If your Univer server requires authentication via cookies, you can set the 'cookie' header here.      cookie: 'your-cookie',      // ... more headers    },  })  univer.registerPlugin(UniverCollaborationClientNodePlugin)}

Runtime notes

loadDocAsync() loads a document that already exists on the server, so createDocument() is not required. The collaboration service identifies the user and checks permissions from the authentication information, such as the Cookie in customHeaders. The server returns the connection's memberID.

The example disables browser offline caching and the single-active-instance lock across tabs, so setCurrentUser() is not required for cache isolation between accounts. If features that depend on a local current user, such as comments, are added later, the application user can be set through UserManagerService. This does not replace server authentication.

The header/footer example applies only to paged documents, and the column example applies only to modern documents. The example checks the document mode with isModern() and skips the operations that do not apply.

The example inserts content into an existing document, so use a test document. The collaboration connection also stays open after the example finishes. Open the same document in a browser to see the changes. flush() waits for the server to acknowledge the queued collaboration changes. For a one-shot script, call univer.dispose() after all asynchronous operations and synchronization have completed.

How is this guide?

© 2026 DreamNum Co., Ltd.