- Developer home
- Embed editors
- Plugins
Plugins
Plugins
A plugin adds its own tools to the Word, Excel, PowerPoint and PDF editors: a panel in the editor's side bar, buttons in the editor's own Plugins tab, items in the right-click menu, suggestions at the caret as the person types, or a page that runs in the background. It reaches the document through the Automation API only.
A plugin's package
A plugin is a folder served over https: mroffice-plugin.json (the manifest), its panel and background pages, its scripts, styles and icon. Every file the manifest names is inside the folder.
{
"manifestVersion": 1,
"id": "com.example.qr-code",
"name": "QR code",
"version": "1.0.0",
"description": "Insert a QR code",
"icon": "icon.svg",
"editors": ["docx", "pptx"],
"permissions": ["read", "write"],
"connect": ["https://api.example.com"],
"panel": { "url": "index.html", "title": "QR code", "width": 300 },
"background": { "url": "background.html" },
"ribbon": [{ "id": "open", "label": "QR code", "opens": "panel" }],
"contextMenu": [{ "id": "from-selection", "label": "QR code of the selection", "when": "selection" }],
"inputHelper": false,
"translations": { "de": { "QR code": "QR-Code" } }
}| Field | Meaning |
|---|---|
manifestVersion, id, version | Always 1; a unique reverse-DNS id; a semantic version. |
name, description, author, icon | What the Plugins panel shows, with the icon from the plugin's folder. |
editors | The editors it is offered in: docx, xlsx, pptx, pdf. |
permissions | read (it reads the document) and write (it may change it). A plugin without write is refused every method that writes. |
connect | The https origins the plugin's pages may call (its own folder is always allowed). Nothing else is reachable. |
panel, background | Its panel (shown in the side bar) and its background page (runs from the start, hidden); a plugin has at least one. |
ribbon, contextMenu, inputHelper | Its ribbon buttons, its right-click items (when: selection shows one only with text selected), and whether it offers input-helper suggestions. |
translations | Its labels in other languages, by locale; plugin.tr reads them. |
The plugin runtime
The editor puts MR Office's plugin runtime at the top of every plugin page, as window.MROffice.plugin, and connects it to the editor over a channel of its own.
<!doctype html>
<html>
<body>
<button id="upper">UPPER CASE</button>
<script>
const plugin = MROffice.plugin;
plugin.ready.then((info) => {
document.getElementById("upper").onclick = async () => {
const { text } = await plugin.word.getSelection();
await plugin.word.insertText(text.toUpperCase());
plugin.ui.notify(plugin.tr("Done"));
};
plugin.onCommand("open", (event) => console.log(event.source, info.kind));
plugin.on("selectionChange", (event) => console.log(event.text));
});
</script>
</body>
</html>| API | What it does |
|---|---|
plugin.ready | Resolves when the editor has connected: the plugin's id and version, the file's kind, the session's mode, the locale, the theme, its permissions and the options your embed config gave it. |
plugin.word, .excel, .powerpoint, .pdf, .document, .getCapabilities() | The whole object model, as a host page has it, checked against the plugin's permissions and the session. |
plugin.on(event, listener) | Listen for selectionChange, contentChange and documentReady. |
plugin.onCommand(id, listener) | Run code when the person chooses one of the plugin's buttons or menu items. |
plugin.ui.openPanel(), closePanel(), notify(text) | Show or close its panel, or show a short notice in the editor. |
plugin.onInput(listener), plugin.ui.setInputHelper(items) | Offer suggestions at the caret as the person types (onInput gives the word before the caret); the choice arrives through onCommand. |
plugin.tr(text) | A label in the editor's language, from the manifest's translations. |
Sandbox and security
- Each plugin page runs in a sandboxed frame with an opaque origin: it cannot read the editor's cookies, storage or session token, nor the page around the editor.
- Its Content-Security-Policy is made from its manifest: scripts, styles, pictures and fonts from its own folder only, network to its folder and the origins it declares, no other frames, forms or navigation.
- Everything it does passes through one message channel to the Automation API, under the session's rights and its own permissions. A view session gives it nothing to write.
- The manifest a workspace installed is the one the editors use: a plugin cannot widen its permissions by changing the files it serves later.
Ship plugins with your embed
Name plugins in open()'s plugins option. options reach the plugin as (await plugin.ready).options; connect grants it more origins, such as your own endpoint. ui.features.plugins: false turns plugins off.
MROffice.open({
container: "#editor",
token,
plugins: [
"https://cdn.example.com/plugins/qr-code/mroffice-plugin.json",
{
url: "https://mroffice.ai/plugins/samples/translate/mroffice-plugin.json",
options: { endpoint: "https://api.example.com/translate", target: "de" },
connect: ["https://api.example.com"],
},
],
ui: { features: { plugins: true, macros: true } },
});Plugins for a workspace
In MR Office itself, people install plugins for their workspace on Settings > Plugins: the samples, or any plugin by its manifest URL. The page shows what each plugin may do before it is installed, and every editor of the workspace offers the installed ones.
ONLYOFFICE plugins
- A plugin written for ONLYOFFICE (its config.json, its pages and window.Asc.plugin) runs in MR Office as it is: name its config.json wherever an mroffice-plugin.json can be named.
- MR Office gives it window.Asc.plugin on its own object model: init, button, onTranslate and tr, onThemeChanged, executeMethod, callCommand with Asc.scope, attachEditorEvent, and context-menu and toolbar items. The Document Builder calls a callCommand makes run as one Undo step.
- Its sdkjs-plugins scripts are MR Office's own, and it runs in the same sandbox as any plugin: it reaches the network only through the origins you grant it with connect.
Sample plugins
| Manifest | Plugin |
|---|---|
https://mroffice.ai/plugins/samples/qr-code/mroffice-plugin.json | QR code: a QR code of a link or the selection, inserted as a picture in Word and PowerPoint. |
https://mroffice.ai/plugins/samples/translate/mroffice-plugin.json | Translate selection: the selection, sent to the translation endpoint you configure, put back in place or added as a comment. |
https://mroffice.ai/plugins/samples/word-count/mroffice-plugin.json | Word count and readability: words, characters, sentences, Flesch reading ease and grade level, kept up to date as the person types. |