Debugging

While writing complex logic, you might be in the cycle of testing/debugging your code. Although UDT -> Debug lets you set breakpoints and debug your code using Chrome Debug Tool, these couple of techniques may also prove handy.

System requirements

Please make sure your local environment uses the following application versions before proceeding.

Console logs

data-slots=heading, code
data-repeat=1
data-languages=JavaScript

JavaScript

async function foo() {
    console.log("foo"); // writes "foo" to the UXP Developer Tool console.
    console.error("foo error"); // does the same thing, but the text is shown in red so errors are more easily seen.
}

Alerts

Create a modal dialog that pauses the execution of your script/plugin until you dismiss it.

data-slots=heading, code
data-repeat=1
data-languages=JavaScript

JavaScript

function alert(msg) {
    const { app } = require("indesign");
    const dialog = app.dialogs.add();
    const col = dialog.dialogColumns.add();
    const colText = col.staticTexts.add();
    colText.staticLabel = `${msg}`;

    dialog.canCancel = false;
    dialog.show();
    dialog.destroy();
    return;
}

async function foo() {
    alert("foo");
}

Additional notes