Get Started
Plugins
Macros
More information

Debugging

To debug ONLYOFFICE macros, follow the instructions below. There are two ways to run a macro in the debug mode.

Option 1. Using the breakpoints

  1. Open the Plugins tab and click Macros.
  2. Use the log method of the console object in your script to display the logging information in the browser debug console:

    console.log(123);
    var oDocument = Api.GetDocument();
    var oParagraph = oDocument.GetElement(0);
    oParagraph.AddText("Hello world!");
    
    Console log
  3. Press the Run button to run your script.
  4. Open the debug console by pressing the F12 button.
  5. Click the debugger:///VM(XXX) link on the right of the line with the logging message. The VMXXX file with your script will be opened.

    Debug console
  6. Set a breakpoint by clicking the line number and run your script again.

    Breakpoint

Script execution is paused, and now you can see the current values of variables, execute commands in the console, etc.

Option 2. Using the debugger command

  1. Open the Plugins tab and click Macros.
  2. Use the debugger command in your script:

    debugger;
    var oDocument = Api.GetDocument();
    var oParagraph = oDocument.GetElement(0);
    oParagraph.AddText("Hello world!");
    
  3. Open the debug console by pressing the F12 button.
  4. Press the Run button to run your script.

    Please note that the debugger command will only work if the development tools are open. Otherwise, the browser will ignore it. Debugger

The debugger command works as a breakpoint and pauses the execution at the script point where this command is inserted.