- Inicio para desarrolladores
- Insertar editores
- Referencia de postMessage
Referencia de postMessage
Referencia de postMessage
Si crea su propio host de marco en lugar de usar embed.js, este es el protocolo completo. Inserte en un marco https://mroffice.ai/<locale>/embed/v1/<app id>; espere el mensaje hello de ese iframe y ese origen; responda a init con el token. Compruebe event.source y event.origin en cada mensaje y pase siempre el origen del editor como targetOrigin.
// Every message, both ways:
{ "source": "mroffice-embed", "version": 1, "type": "<type>", "id": "<optional request id>", "payload": { … } }
// Host page → editor (targetOrigin: the editor's origin, never "*")
init { token, theme?, ui?: { brand?, toolbar?, features? }, downloads?, sdk? } answer to "hello"; once per boot
users { users: [{ id, name, email?, avatarUrl? }] | null } answer to "requestUsers" (same id); null: no directory
requestSave {} → "saved" or "error" with the same id
setMode { mode, token } → "modeChanged" (a token signed for that mode)
refreshToken { token } answer to "tokenExpiring"
setTheme { theme: "light" | "dark" | "system" }
openFile { name, type, data: ArrayBuffer } → "fileOpened" or "error" with the same id (transfer data; file.local tokens)
focus {} moves the keyboard focus into the document
command { method, params, apiVersion: 1 } the Automation API → "commandResult" with the same id
destroy {} → "destroyed"
// Editor → host page (sent to the origin that sent "init" only)
hello { appId, boot, protocol: { version, capabilities } }
the editor is listening; send "init". A new boot (the frame was reloaded) needs a new init, with a
fresh token; capabilities lists what this frame can do (openFile, focus, connection, reinit, …)
awaitingFile { accept, maxBytes, canOpen } a file.local token, no file yet: the editor shows its drop zone
fileOpened { name, size, type } a file from the person's computer was opened ("ready" follows)
ready { mode, effectiveMode, modeNote?, permissions, watermark, user,
document: { key, name, kind, format, version, partnerVersion }, expiresAt }
change { dirty, modified } dirty: edits on their way to the server; modified: since the last save
saveRequested { reason: "user" | "host" }
saved { saveId, unchanged, version, sha256, size, downloadUrl, downloadExpiresAt }
download { name, handledBy, url?, mimeType?, size?, data? } a file the editor saved (export, picture, PDF pages):
handledBy "frame" (the browser saved it), "host" (downloads: "host": data is an ArrayBuffer, transferred,
or url a short-lived link) or "refused" (ui.features.export is false, or the token's permissions)
error { code, message, fatal }
modeChanged { mode, effectiveMode }
requestUsers { query } the comment box's "@": answer "users" with the same id within 4 s
usersChanged { users: [{ id, name, avatarUrl, color, mode, since }], self } who is in the document now
mention { threadId, commentId, text, mentioned: [{ id, name, email }] } a comment naming people was posted
tokenExpiring { expiresAt } about 5 minutes before the session ends
connection { online } the editor lost (false) or regained (true) its link to MR Office
commandResult { ok: true, result } | { ok: false, error: { code, message, details? } } answer to "command"
destroyed {}