- Developer home
- Embed editors
- Use MR Office as a WOPI app
Use MR Office as a WOPI app
This page is not yet translated into your language; it is shown in English.
Use MR Office as a WOPI app
MR Office is a WOPI client, the role Office for the web and Collabora Online play. A WOPI host that already integrates one of them (Nextcloud, ownCloud, Seafile, a document management system or your own) can open .docx, .xlsx, .pptx and .pdf files in MR Office instead. The host keeps the file: MR Office reads it with CheckFileInfo and GetFile and writes it back with PutFile, under a WOPI lock.
Code files and handwriting documents (.mrink) are not offered to WOPI hosts: no WOPI client lists such an application, and a host that maps by MIME type would hand MR Office every source file of its users. Open them with embed.js and a session token.
Set up
- In the developer console, open your app and list its WOPI hosts: the WOPISrc prefix of your files, for example https://cloud.example.com/index.php/apps/richdocuments/wopi/files. Only files under these prefixes open, and pages on these hosts' origins may frame the editor.
- Point your host at the app's discovery: https://mroffice.ai/hosting/discovery?app=<app id>. A host that asks for a WOPI server URL and adds /hosting/discovery itself (Nextcloud, ownCloud) takes https://mroffice.ai/api/v1/wopi/<app id>.
- Your host page frames an action URL from discovery and POSTs access_token and access_token_ttl to it, as it does for Office for the web. The editor opens in the frame; there is no SDK and no token to sign.
<!-- Your host page: as for Office for the web. urlsrc is the discovery action
for the file's extension (placeholders filled or removed), WOPISrc your file. -->
<form id="office_form" name="office_form" target="office_frame" method="post"
action="https://mroffice.ai/api/v1/wopi/APP_ID/edit?ui=en-US&WOPISrc=https%3A%2F%2Fcloud.example.com%2Fwopi%2Ffiles%2F42">
<input name="access_token" value="ACCESS_TOKEN" type="hidden">
<input name="access_token_ttl" value="1763800000000" type="hidden"> <!-- ms since the epoch -->
</form>
<iframe id="office_frame" name="office_frame" title="MR Office" allowfullscreen
allow="clipboard-read; clipboard-write" style="width:100%;height:100%;border:0"></iframe>
<script>
document.getElementById("office_form").submit();
window.addEventListener("message", (event) => {
if (event.origin !== "https://mroffice.ai") return;
const message = JSON.parse(event.data); // { MessageId, SendTime, Values }
if (message.MessageId === "App_LoadingStatus") {
document.getElementById("office_frame").contentWindow.postMessage(
JSON.stringify({ MessageId: "Host_PostmessageReady", SendTime: Date.now(), Values: {} }),
"https://mroffice.ai",
);
}
if (message.MessageId === "UI_Close") history.back();
});
</script>Discovery
Discovery lists, per extension, an app named as Office for the web names it (Word, Excel, PowerPoint, Pdf) with the actions view, edit, editnew and embedview (PDF: no editnew). Their urlsrc carry Microsoft's placeholders <ui=UI_LLCC&>, <rs=DC_LLCC&>, <thm=THEME_ID&>, <dchat=DISABLE_CHAT&>, <embed=EMBEDDED&>, <hid=HOST_SESSION_ID&> and <sc=SESSION_CONTEXT&>: fill or remove them, then add WOPISrc. For hosts that look actions up by MIME type (Nextcloud, ownCloud) it also lists an app per MIME type whose edit urlsrc ends with ? and carries no placeholder, Collabora's Capabilities app, and the <proof-key> element. Edit actions require update only: a host without locks is edited too.
Discovery also lists the other formats the embedded editor opens and saves back in their own format (.doc, .dot, .rtf, .odt, .dotx, .txt, .md, .html, .xls, .ods, .csv, .tsv, .xltx, .ppt, .odp, .potx) under the same applications. Plain text, Markdown, CSV and HTML are not listed by MIME type, so a Nextcloud or ownCloud keeps opening them in its own apps.
What MR Office implements
| WOPI operation | MR Office |
|---|---|
CheckFileInfo | At every launch, as the person. Read: BaseFileName, Size, Version, UserId, UserFriendlyName, IsAnonymousUser, UserCanWrite, ReadOnly, WebEditingDisabled, SupportsUpdate, SupportsLocks, SupportsRename, UserCanRename, UserCanNotWriteRelative, PostMessageOrigin, the Breadcrumb… properties, ClosePostMessage / CloseUrl, EditModePostMessage / HostEditUrl, EditNotificationPostMessage, FileSharingPostMessage / FileSharingUrl, FileVersionPostMessage / FileVersionUrl, DisablePrint, and Collabora's DisableExport / HideExportOption / HidePrintOption. |
GetFile | When MR Office does not hold the file at the host's Version (a new file, or a newer version while nobody has it open). X-WOPI-MaxExpectedSize is the app's file size limit. A 0-byte file (editnew) opens as a blank document of its kind. |
Lock, RefreshLock, Unlock | One lock per file for everyone editing it together: taken when an edit session opens, refreshed every 10 minutes, released once the last person has left and the closing save is written. A file another client has locked opens read-only. |
PutFile | Every save: Save in the editor, a save 30 seconds after the last change, an autosave every 5 minutes while someone edits, and the closing save when everyone has left. Sent with X-WOPI-Lock and X-WOPI-Editors; X-WOPI-ItemVersion (or a new CheckFileInfo) is the version MR Office then holds. |
PutRelativeFile | Save a copy, with X-WOPI-SuggestedTarget (UTF-7), when UserCanNotWriteRelative is not true. The copy's Url is never shown; HostEditUrl is offered. |
RenameFile | Renaming the file in the header, with X-WOPI-RequestedName (UTF-7), when SupportsRename and UserCanRename. |
GetLock, UnlockAndRelock, containers, ecosystem, PutUserInfo, Cobalt | Not used. |
Proof keys
Every request MR Office sends a host is signed as Office for the web signs: X-WOPI-Proof with the current key, X-WOPI-ProofOld with the previous one, and X-WOPI-TimeStamp. Discovery's <proof-key> publishes both keys as .NET CSP blobs (value, oldvalue) and as modulus and exponent. Verify as Microsoft documents: accept Proof with the current key, ProofOld with the current key, or Proof with the old key; refuse a timestamp older than 20 minutes; fetch discovery again when a request does not verify. Keys rotate with an overlap, so a host whose discovery is cached keeps verifying.
PostMessage
| Message | When |
|---|---|
App_LoadingStatus | Status Frame_Ready when the frame runs, then Document_Loaded with DocumentLoadedTime when the document shows, or Failed when it cannot open. |
Edit_Notification | The first edit, then at most every 5 minutes (EditNotificationPostMessage). Collabora's Doc_ModifiedStatus is sent as well. |
UI_Close | Close in the header (ClosePostMessage), after saving what changed; otherwise the frame goes to CloseUrl. |
UI_Edit | Edit in a read-only view (EditModePostMessage); otherwise HostEditUrl. |
UI_Sharing, UI_FileVersions | Share and Versions (FileSharingPostMessage, FileVersionPostMessage); otherwise FileSharingUrl and FileVersionUrl, in a new tab. |
File_Rename | After a rename, with NewName. |
From the host | Host_PostmessageReady, Grab_Focus, Blur_Focus, and Collabora's Action_Save (answered with Action_Save_Resp) and Action_Close. |
Messages are JSON strings, posted to PostMessageOrigin only and never to "*". Messages other than App_LoadingStatus wait for Host_PostmessageReady, or 10 seconds for a host that never sends it.
Conflicts and failures
- A lock held by another client (409 with another X-WOPI-Lock) fails the save and overwrites nothing; the person can save a copy. A lock that lapsed is taken again and the save retried once.
- A host without locks is written only while CheckFileInfo's Version is still the one MR Office read or wrote; a file changed meanwhile fails the save with wopi_file_changed.
- A file changed on the host while nobody has it open in MR Office is read again at the next launch. While people have it open, a launch at another version is refused (wopi_file_changed_while_open).
- An access_token_ttl in the past, or a 401 from the host, opens nothing. When no editor holds a valid token any more, nothing is written and the person opens the file from the host again.
- A refused launch shows its reason in the frame, posts App_LoadingStatus Failed and is listed in the console's Events. MR Office calls only WOPISrc URLs under the app's WOPI hosts, over https to public addresses, and follows no redirect.
Nextcloud, ownCloud and Seafile
- Nextcloud: install Nextcloud Office (richdocuments), choose Use your own server, and enter https://mroffice.ai/api/v1/wopi/<app id> as the URL of your WOPI server. In the app's WOPI hosts, list https://<your Nextcloud>/index.php/apps/richdocuments/wopi/files (without index.php when Nextcloud has pretty URLs).
- Nextcloud's Allow list for WOPI requests refuses calls from addresses it does not list: leave it empty, or add the addresses MR Office's servers connect from (ask [email protected] for them).
- Nextcloud and ownCloud read /hosting/capabilities: MR Office answers as a WOPI server that is not Collabora (no templates from the host, no conversion service), so the host's own new-file templates are used.
- ownCloud: the same WOPI server URL in its Office app; list the WOPISrc prefix its requests use (shown in the WOPISrc parameter of the frame's URL).
- Seafile: OFFICE_SERVER_TYPE = 'CollaboraOffice', ENABLE_OFFICE_WEB_APP = True, OFFICE_WEB_APP_BASE_URL = 'https://mroffice.ai/hosting/discovery?app=<app id>', ENABLE_OFFICE_WEB_APP_EDIT = True and the four extensions in OFFICE_WEB_APP_FILE_EXTENSION and OFFICE_WEB_APP_EDIT_FILE_EXTENSION; list Seafile's WOPISrc prefix as the WOPI host.
Usage, limits and security
Every launch is a session of the app: it counts toward the app's sessions, documents, editors and saves, and the plan's limits apply, as for embed.js sessions (a WOPI host on localhost counts as development). The host's access token is kept encrypted for the session's lifetime and is only ever sent to the file's WOPISrc. The editor's session reaches its own file and nothing else of MR Office.
Try it with the reference host
The repository's reference WOPI host serves a folder over WOPI, frames MR Office the way a host does, and checks every request MR Office makes (proofs included) against your app's discovery.
# The reference WOPI host in the MR Office repository: a folder served over WOPI,
# verifying every request's proof against your app's discovery
python3 tools/wopi-reference-host/wopi_host.py --root ./files --port 9876 \
--discovery "https://mroffice.ai/hosting/discovery?app=APP_ID" \
--user alice:Alice:write --user bob:Bob:read
# WOPI host to list in the console: http://127.0.0.1:9876/wopi/files
# (http on localhost is for an API running locally; a host MR Office's
# servers reach must be public https)