How to debug macros!

Hi there,
im starting to get used to writing Macros.

Im on Manjaro Linux and i dont know where to find a debug-log if i made errors programming my Macro.

Ive got one which does not work correctly but no error sign is shown in the editor.
Is there a log for executed macros?

Thx

Hello @Kaligula
There’s no any approach or tool which we can recommend you to debug macros code. Also, there are no logs for executed macros.

Sorry for inconvenience.

Hello everybody,

In order to „debug“ a macro, I wonder, if there is a way to display variable values etc. in some kind of alert-function, but it says in the introduction to macros that they are restricted? Am not sure from that, wether there is a way of displaying an alert or something similar?

1 Like

Hello @Dimpflmoser
Please clarify your request. What do you mean by alert-function?

Hi Alexandre,

I mean to present messages to the user / developer from JavaScript, for example something like:
let count = 100;
alert (count + “data processed“);
Or just print some value:
alert(count);
Quite similar to the usage of alert in plain JavaScript, just a means to easily present messages to developer / user.
Thanks a lot

Hello @Dimpflmoser
You can use console (console.log()) method for debugging. Unfortunately, alert feature use is not possible at the moment (we are working on it already).
Sorry for inconvenience.

Hello,

thanks for the response. I am also trying to develop a macro and depsite having spent some time coding, I find access logs particularly convoluted.

I see on this page:

  • we can use the --ascdesktop-support-debug-info flag so I did that
  • then what. Where do the logs go? do we type console.log("hello world");? I ran journalctl --follow as I normally would but nothing appears in the logs. Where is the console.log output?
  • it says " right-click any editable field on the top toolbar (for example, font list combo) and click Inspect Element" but nothing happens when I right click anywhere…
  • Also, why does this flag need to be in the command line rather than being an option in the settings in the first place?

I see from this page:

  • " 4. Open the debug console by pressing the F12 button.": Nothing happens when I presse F12. I found that I can right click on the bar in the middle to select “Show Devtools”
  • “5. Click the debugger:///VM(XXX) link on the right of the line with the logging message”: there is no such thing
  • “6. Set a breakpoint by clicking the line number and run your script again.”: Nothing happens when I click on a line number. How can I set breakpoints?
  • Why isn’t there a “debug” button in the macro editor to access this console rather than expecting people to find this?

Using OnlyOffice 7.2.1 as flatpak on Ubntu 22.10.

Hello @Batwam
We are checking the situation. I will update this thread when we have something to share.

The mentioned guide in this part of your post is related to server-based solution (F12 button for browser action). We are checking the situation with ‘right click’.

Update:
Thank you for pointing us to the situation with ‘right-click’, we are going to fix it with v.7.3.
As for other questions:

  • Also, why does this flag need to be in the command line rather than being an option in the settings in the first place?
  • Why isn’t there a “debug” button in the macro editor to access this console rather than expecting people to find this?

We designed Desktop Editors this way, because a user doesn’t need debug mode in most common scenarios of work with Desktop Editors. But I understand and noted your suggestion, probably one day we will come back to it.
Thank you one more time!

Hello @Batwam
We have released v.7.3. Please update Desktop editors and double-check the situation.

Yeah, I just saw the announcement on reddit, it’s great you are releasing the Linux version at the same time as the rest. I’ll have a look.

1 Like

ok, it looks like th eflatpak hasn’t been released yet so I’ll have to wait a little bit. Is there a timeline for flatpak release?

Hello @Batwam

Sorry for the late response.
We are planning to release it during a week.

Hello again @Batwam

We have release Desktop Editors v7.3 for flatpak.
Please update your current instance and check out the situation.

ok so, I had a look at v7.3 and couldn’t spot any difference.

Regarding the first page on Debugging, this has more to do with app debugging which isn’t what I was trying to do so that’s my mistake and we can ignore.

On the second page regarding macro debugging, again, no change as far as I can tell. DevTools is a very useful tool but for some reason it is burried quite deep and hidden behind this right click → Show DevTools. Pressing F12 still does nothing for me and quite frankly, even if it did, there should be a button so the user knows it’s there. A debug console is a critical tool when writting macros, I really think that this DevTools window should be made more visible.

Ideally, it should be integrated directly in the Macros window. It doesn’t need to be massive, perhaps a split screen at the bottom of the code like in VS Code would do. In any case, please add a button to show DevTools (e.g. next to “Run”) of people aren’t going to know it’s there.

Also, the window can’t be resized and 1/4 of the screen size is too small for some decent code, would it be possible to allow resizing so it can be made full screen and allow hiding/resizing the left panel? the left panel is taking too much valuable real estate in this window at the moment.

You mentioned the guide which is related server-based Document server (stand alone installation of entire Document server). This way F12 works properly. For Desktop editors you have to use F1 button as it is described here: ONLYOFFICE Api Documentation - Debugging

About Macros tab screen re-size, we have noted your requested and will discuss it internally.

Hello @Kaligula
My approch for macro debugging is to wrap my code with following Skeleton.
Its allows to LOG any strings one after one to a choosen worksheet column.

> (function() {
>     var oTraceRange = Api.GetActiveSheet().GetRange("L1");
>     oTraceRange.Clear();
>     function LOG(trace = "on y passe") {
>         oTraceRange.SetValue(trace);
>         oTraceRange.SetOffset(1, 0);
>         oTraceRange.Clear();
>     }
>     try {
>         LOG("Skeleton");
>         // Here to write incoming you code ....
>     }
>     catch (e) {
>         LOG(e);
>     }
>     LOG("fini");
> 
> })();

You may also dedicate a full worksheet for logs : oTraceRange = Api.GetRange(“trace!A1”);

1 Like

Thank you for sharing your experience @jpp
Just to add a few words, you can check console logs in web-browser for running macro with this section that has been added to macro itself:

    console.log(text.constructor.name)
    console.log(text.toString())
})();

I hope it will be useful.

Hi!
It’s my decision for using like alert function:
const msg = (m, t = 'Message') => { Common.UI.alert({ msg: m, title: t }) };

Now you could use this:
msg('Hello, world!);

1 Like

Hello @malubimcev
Are you adding these lines to macro itself? Could you please share a sample with detailed usage scenario?