Do you want to: Ask a how-to question
Document Server version: 9.0.3
Type of installation of the Document Server: docker with onlyoffice/documentserver:9.0.3 image
Host OS: Debian 12 (Bookworm)
Browser version: Mozilla Firefox 128.13.0esr
I want to interact from the editor (browser - client side) to custom plugin. I’m using iframe.contentWindow.postMessage method to send a post message to editor’s iframe. By referencing sdkjs-plugins repository and it’s externallistener example the plugin implementation should look like this:
(function (window, undefined) {
window.Asc.plugin.onExternalPluginMessage = function (data) {
switch (data.type) {
case "insertText": {
Asc.scope.text = data.text; // export variable to plugin scope
this.callCommand(function () {
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.AddText(Asc.scope.text);
oDocument.InsertContent([oParagraph]);
}, false);
break;
}
}
};
})(window, undefined);
I also registered my pluign properly to the following path
/var/www/onlyoffice/documentserver/sdkjs-plugins/insert_tool
Here is my postMessage call as an example:
function onAppReady() {
const editorIframe = document.querySelector('iframe[name=frameEditor]');
editorIframe.contentWindow.postMessage({
type: "onExternalPluginMessage",
pluginGuid: "asc.{A8705DEE-7544-4C33-B3D5-168406D92F72}",
data: {
type: "insertText",
text: "test text"
}
}, "https://onlyoffice.example.local");
console.log("ONLYOFFICE Document Editor is ready")
};
editorConfig.events = { onAppReady };
const docEditor = new DocsAPI.DocEditor("frameEditor", editorConfig);
what is the problem of my implementation ?