Editor embedding
Editor embedding
Open the O3O Office Online editor in an iframe on any web page with api.js and O3O.Editor, without Nextcloud or WOPI.
On this page
The embed layer lets any web page open the O3O Office Online editor in an <iframe>, without Nextcloud or a WOPI-speaking storage system. Your page needs just two things: a URL the O3O server can download the source file from, and (if you want the edited copy back) a callback URL.
Components#
| Component | Role | Runs where |
|---|---|---|
api.js (/o3o/api.js) | Plain JavaScript library, no dependencies, no build step. Exposes window.O3O with O3O.Editor and O3O.version. | Browser |
| o3o-gate | Creates embed sessions, downloads the source file, applies the connection cap, acts as the internal WOPI host, keeps versions, sends HMAC-signed callbacks. | O3O server, behind the /o3o/ path |
| Editor server (o3o-online) | The collaborative editor shown in the iframe. | O3O server, behind /browser and /cool |
| Your server | Serves the source file by URL, signs the config with JWT, receives callbacks and stores the edited copy. | Your infrastructure |
What happens when a document opens#
- Your page loads
http://localhost:8080/o3o/api.jsand callsnew O3O.Editor("id", config).api.jsderives the server address from thesrcof its own script tag. api.jsposts the config (withoutevents) toPOST /o3o/embed/session.- The gate checks the origin and JWT, downloads
document.urlunder the SSRF rules, applies the connection cap, then returns the editor address with the sessionaccess_token. api.jsbuilds the iframe and submits a form POST into it; the token travels in the form body, never in a URL.- The editor server reads the file from the gate over the internal network. On save, the gate stores a new version, answers the editor server at once, then sends a callback to
callbackUrl. - Your page receives events via
postMessage:onReady,onDocumentLoaded,onModified,onSaved,onClose,onLimitReached,onError. - Once everyone has left for 30 seconds, the gate sends a
closedcallback, keeps the working copy for 24 hours, then deletes it.
Shortest example#
<!-- Minimal HTML page, runs on a DEV machine (O3O_DEV_MODE=1) -->
<div id="o3o-editor" style="height: 720px"></div>
<script src="http://localhost:8080/o3o/api.js"></script>
<script>
const editor = new O3O.Editor("o3o-editor", {
document: {
url: "http://localhost:8080/o3o/demo/sample.docx",
title: "sample.docx",
fileType: "docx",
key: "sample-1"
},
editor: { mode: "edit", lang: "en-US", user: { id: "u-1001", name: "Jane Doe" } },
events: {
onDocumentLoaded: () => console.log("loaded"),
onSaved: (e) => console.log("saved version", e.version),
onError: (e) => console.error(e.code, e.message)
}
});
</script>When to use the embed layer#
| You need | Use |
|---|---|
| Open a file by URL in your own web app and get the edited copy back | The embed layer (this section) |
| Your users already work in Nextcloud | Nextcloud |
| Keep permissions and history in your own system, with the editor server calling your store directly | Build a WOPI host |
| Convert or generate documents with nobody opening them | DocBuilder |
What v1 includes#
O3O.Editorwith 7 events and 5 methods.- Config signing with JWT HS256; HMAC SHA-256 signed callbacks.
- Two modes,
editandview;viewsessions do not count as connections. - Connection cap reached: new sessions open read-only with a Vietnamese banner; open sessions are never cut and saves are never blocked.
- Keeps the 5 latest versions plus the original for 24 hours; signed download URLs.
- SSRF rules for every URL the server calls itself; a
/o3o/demotest page on DEV machines.
Coming soon
Dark theme, watermarks, per-button visibility, save as a new file, creating a blank document without a url, version history in the UI, white label (logo, name, colours) for the enterprise edition.