To debug a macro

Since macros are written in JavaScript and executed in the browser, the best way to debug and troubleshoot them is by using your web browser’s built-in tools. Modern browsers come with a very capable set of tools for debugging JavaScript code. You can place breakpoints, step through code, and output debug information.

HINT:JavaScript is case sensitive. Keep that in mind when editing JavaScript code.

To debug a macro:

  1. Open the macro for editing. See To edit a macro for instructions.

  2. Open your browser’s development tools.

    Table 10 Browser debugging support

    Browser

    Open debugger

    Mozilla Firefox 40.0.3

    • From the toolbar, open the Menu, and choose Developer.

    • From the Web Developer menu, choose Debugger. The debugger opens in a lower panel.

    Google Chrome 45.0

    • From the toolbar, open the Menu, and choose More tools.

    • Choose Developer Tools to open the Debugger.

    Microsoft Internet Explorer 11

    • From the toolbar, open Settings, and choose F12 Developer Tools.

    • Open the Debugger tab.

    These instructions are for supported browsers and are dependent on the versions used.

  3. Use one of the these tools in your macro code, and run the code.

    • debugger

      The most thorough approach to debugging is to use the ‘debugger;’ statement. When you insert these statements into your macro code then run it, with the browser’s development tools open, the execution will stop on those lines. You can step through your macro, view the value of local variables and whatever else you need to check.

      You are encouraged to place multiple debugger; statements in your code to help get to the correct line. The asynchronous nature of JavaScript can make stepping through code challenging. This can be offset by using multiple, carefully placed debugger; statements.

      Example 1 Debugger

      ---------------------
      var hostCommand = menuSelection + ‘[enter]';
      debugger;  // <— Browser's debugger will stop here
      ps.sendKeys(hostCommand);
      ---------------------
    • console.log(), alert()

      These two functions are commonly used for debugging JavaScript. While not as flexible as the debugger statement they provide a quick way to output debug information. These functions output the information to the JavaScript “Console” tab in the browser’s developer tools.

      Example 2 console.log(), alert()

      ---------------------
      var hostCommand = menuSelection + ‘[enter]';
      console.log('Command:' + hostCommand);  // <— Will output the string to "Console" tab
      alert('Command:' + hostCommand); // Will pop up a small window containing the data
      ps.sendKeys(hostCommand);
      ---------------------
    • ui.message()

      The Reflection ZFE Macro API provides an ui.message() function that is very similar to JavaScript’s alert() function. You can also use ui.message() to output debug information.

      Example 3 ui.message()

      ---------------------
      var hostCommand = menuSelection + ‘[enter]';
      ui.message('Command:' + hostCommand);  // <— Will pop up a ZFE message window
      ps.sendKeys(hostCommand);
      ---------------------