Hello,
I am integrating the OnlyOffice Document Editor into my web application (built with React and a Flask backend). My application has a “deep search” feature that allows users to find documents based on their content.
When a user clicks on a document from these deep search results, I want the embedded OnlyOffice editor to automatically:
-
Open its internal “Find” or “Search” panel.
-
Pre-fill this panel with the search term the user originally used in my application.
-
Ideally, highlight all occurrences of this term within the loaded document.
Essentially, I’m trying to replicate the behavior of a user pressing Ctrl+F, typing the search term, and seeing the results highlighted, but I want to trigger this programmatically when the document loads with a specific search context.
I am using the DocsAPI.DocEditor JavaScript API for embedding. I initialize the editor with a configuration object that includes the document URL, permissions, user info, etc. My frontend DocumentView object contains the searchQuery (e.g., “text”).
What I’ve Tried (and hasn’t worked from the host page):
-
editorConfig.customization.search: I initially thought I could pass a search array in the editorConfig.customization object during initialization. This does not seem to be a supported parameter for this purpose.
-
docEditor.searchText(…): I tried calling a hypothetical searchText method on the docEditor instance (the object returned by new DocsAPI.DocEditor(…)) in the onDocumentReady event. This resulted in a “searchText is not a function” error.
-
docEditor.executeMethod(“ShowSearchDialog”, [query, …]): also tried this.docEditor.executeMethod(“ShowSearchDialog”, [searchTerm, false, false, false, true]) in onDocumentReady. This resulted in a “this.docEditor.executeMethod is not a function” error, indicating that the executeMethod available to plugins via window.Asc.plugin.executeMethod is not directly exposed on the DocsAPI.DocEditor instance available to the embedding page.
My Question:
Is there a supported method or a sequence of calls using the DocsAPI.DocEditor JavaScript API (available to the host/embedding page) that allows me to programmatically initiate a search within the loaded document, pre-fill the search term, and have occurrences highlighted when the document view is opened?
If this is not possible directly via the embedding API, what would be the recommended approach? Is developing a custom OnlyOffice plugin the only way to achieve this level of UI control from the host application’s context?
Any guidance or examples would be greatly appreciated.