- Developer home
- Embed editors
- JavaScript SDK
JavaScript SDK
JavaScript SDK
embed.js (https://mroffice.ai/embed/v1/embed.js, about 10 KB gzip, no dependencies) defines window.MROffice; the same code is the mroffice-embed package. MROffice.open(options) returns a handle.
| Option | Meaning |
|---|---|
container | An element, or a selector for it. The editor fills it (give it a height). |
token | The session token, or (better) a function returning a promise of one. A function is called again whenever a fresh token is needed, with { reason: "start" | "refresh" | "reload" | "mode", mode }. |
refreshToken | Returns a promise of a fresh token (default: token, when it is a function): used before the session ends, when the frame is reloaded, and by setMode() and setLocale(). |
appId | Your app ID. With a token function, pass it: the editor's frame starts loading at once, while your server signs the token (otherwise the ID is read from the token's iss first). |
file | file: { name } (optional): the file's name, so the frame starts loading that kind's editor (Word, Excel, PowerPoint or PDF) before the token arrives. The token's file always wins. |
locale | The editor's language: en, de, fr, es, ja, zh, … (default en). |
theme | "light", "dark" or "system". |
ui.toolbar | "full" (default) or "none" (the ribbon hidden: a clean editing surface). |
ui.brand | false hides the small MR Office mark, once MR Office has allowed it for your app (the developer console shows whether it has); otherwise the mark stays. |
onReady, onChange, onSaveRequested, onSave, onError, onModeChange, onDestroy | Events, below. |
onConnectionChange | The editor lost ({ online: false }) or regained ({ online: true }) its link to MR Office; edits typed meanwhile are kept and sent when it is back. |
onAwaitingFile, onFileOpened | A file.local token: no file yet (the editor shows its drop zone), then a file was opened. |
onRequestUsers(query) | The people a comment may @mention, from your own directory: return (or resolve to) up to 50 { id, name, email?, avatarUrl? }. Without it, the people in the document are offered (see Users, presence and mentions). |
onUsersChange, onMention | Who is in the document changed ({ users, self }); a comment mentioning people was posted ({ threadId, commentId, text, mentioned }). |
ui.features | Turn off export, print, versionHistory or comments (each true by default). AI is not part of the embedded editor. |
downloads, onDownload | Who saves the files the editor hands out: "browser" (default; onDownload tells you each one) or "host" (the browser saves nothing; onDownload gets the file as event.blob, or event.url for a short-lived link). |
allow | The iframe's allow attribute (default: the permissions below). |
origin | The editor's origin (default: where embed.js was loaded from). |
| Handle | Does |
|---|---|
ready | A promise of the ready event (rejects on a fatal error). |
requestSave() | Saves now, as the editor's own Save; resolves with the saved event. |
setMode(mode, token?) | Switches to another mode (edit, view, comment, review, fillForms) with a token signed for it. |
setTheme(theme) | Changes the theme. |
setLocale(locale) | Shows the editor in another language: the frame reloads and goes on in a new session on the same document (waits for edits on their way; needs a token function). |
focus() | Moves the keyboard focus into the document. |
openFile(file, name?) | Opens a File or Blob your page holds, for a file.local token; resolves when it is open (see Files from the person's computer). |
destroy() | Ends the session and removes the editor. |
iframe | The iframe element. |
capabilities | What the editor's frame can do (from its hello): openFile, focus, connection, reinit, kindHint, … |
getCapabilities(), document, commands, word, excel, powerpoint, pdf | The Automation API: read and change the open document from your page (see Automation API). |
If the frame is reloaded (by your page, setLocale or a crash), embed.js starts it again with a fresh token from your token function: onReady fires again. Every error carries its code's hint and a docs link (error.hint, error.docs; see Errors and debugging). MROffice.preconnect() opens the connection to the editor ahead of time, as open() itself does.