Hey, I built a simple extension using the JavaScriptExtension class attached to a page. It shows an annotation popup when text is selected on a wiki page.
The script checks for the #xwikicontent div to check if the selection is in the wiki content. After all, it is intended to run only when a wiki page is in regular view mode.
I found the XWiki object that is available in the frontend (used here for example). It contains useful properties like the contextaction (view, admin…) and viewer. When you open the “Information” page of a wiki page, a query parameter ?viewer=information is added in the URL. However, the XWiki.viewer field is still an empty string. ![]()
I also have not found a easy and integrated way to check open wiki page is a 404.
Is there anything I can do in the script to have the guarantee that I can work with the wiki page and not an error page, admin page, viewer page etc.? That I can rely there is actual page content in a simple manner without having to find all edge cases?
Is the XWiki JS API meant to be used by custom scripts, documented somewhere or stable at all? What checks can I use to only run my plugin when a wiki page is opened in regular view mode? It would be nice if I could still log errors when the #xwikicontent div is not found as expected.