Developers · Embed
Embed a Document Editor in Your Web App
Add a DOCX, XLSX, PPTX and CSV editor to your product with a single iframe and a postMessage API. Your app keeps auth, file access and upload — the editor just edits, and never sees your users' tokens.
The editor runs entirely in the browser with the OnlyOffice WebAssembly engine, so documents are rendered and edited on the client — you don't stand up a document server. The recommended pattern keeps a clean boundary: the parent app handles authentication, fetching and saving; the iframe handles editing only. Tokens, cookies and business APIs stay in your app.
Add it with one iframe
<iframe
id="documentEditor"
src="https://edit.chaxus.com/?embed=1&embedOrigin=https://your-app.example.com"
style="width: 100%; height: 720px; border: 0"
></iframe>
Then talk to it over postMessage. Every command takes an id so you can match it to the
reply, and every editor event is a document:* message:
// open a file your app already fetched (auth stays with you)
iframe.contentWindow.postMessage(
{ id, type: 'document:open-buffer', payload: { fileName: 'report.xlsx', buffer } },
'https://edit.chaxus.com'
);
// ask for the edited file back, then upload it yourself
iframe.contentWindow.postMessage({ id, type: 'document:save', payload: { targetExt: 'XLSX' } }, editorOrigin);
// → editor replies with { type: 'document:saved', payload: { fileName, file } }
What you get
- One iframe + a small postMessage command/response API — no SDK to install
- Open from a URL, a File, or an ArrayBuffer your app fetched with its own credentials
-
Save back to XLSX, DOCX, PPTX or CSV, returned as a
Filefor your app to upload - Read-only mode, per-message origin locking (
embedOrigin), and a state query - No document server to run — editing is 100% client-side WebAssembly
- Open source (AGPL-3.0) and self-hostable — embed it under your own domain
How it works
- Add the iframe pointing at the editor with
?embed=1, sized to your layout. -
Wait for the
document:readyevent, then senddocument:open-url,open-fileoropen-buffer. - The user edits in place; the file never leaves the browser unless your app sends it somewhere.
-
Send
document:save; the editor returns the edited file viadocument:saved, which your app uploads with its own auth.
Frequently asked questions
How do I embed the document editor?
Add one iframe pointing at the editor with ?embed=1, then drive it with a postMessage API to open
and save documents. A working demo is at /embed-demo.html.
Does the editor see my users' auth tokens?
No. Auth, file fetching and upload stay in your app — your app fetches the file with its own credentials and passes the bytes to the editor, so tokens and cookies never enter the iframe.
Which file formats can the embedded editor handle?
DOCX, XLSX, PPTX and CSV, edited client-side with the OnlyOffice WebAssembly engine. The save command exports to XLSX, DOCX, PPTX or CSV.
Can I self-host it or use it white-label?
Yes. It's open source under AGPL-3.0 and ships as static files, so you can host your own copy and embed it under your own domain.
How do I restrict which site can talk to the editor?
Add embedOrigin to the iframe URL to lock messaging to a specific origin, and verify
event.origin in your own message handler.