Introduction

This post describes how to debug JavaScript in Alfresco/Share.

There are two types of js files used in Alfresco/Share:

  • client side – they are placed in Share root directory
  • server side – they are placed in the path within WEB-INF/alfresco directory in Share and Alfresco and are used for example for by web scripts

Client side

Share Debugger

To debug JavaScript on client side client-debug and client-debug-autologging flags in Share configuration file share/WEB-INF/classes/alfresco/share-config.xml can be set to true as presented below. That allows to use JavaScript debugger after pressing (Ctrl, Ctrl, Shift, Shift). Setting client-debug to true causes using original *.js files instead of their minimised versions *-min.js. Setting client-debug-autologging to true enables the JavaScript debugger console.

  <flags>
         <!--
            Developer debugging setting to turn on DEBUG mode for client scripts in the browser
         -->
         <client-debug>true</client-debug>
         <!--
            LOGGING can always be toggled at runtime when in DEBUG mode (Ctrl, Ctrl, Shift, Shift).
            This flag automatically activates logging on page load.
         -->
         <client-debug-autologging>true</client-debug-autologging>
      </flags>

Web Browser Debugger

Apart from that standard tools provided by web browsers can be used. They are really great and include:

  • Web Console (Tools -> Web Developer) in Firefox
  • Developer Tools (Tools) in Chrome

Server side

Log file

It is not so straight forward to debug server side script in Alfresco. Therefore there is logging class that saves the logging messages from JavaScript to standard log files/output. To see those change logging level for org.alfresco.repo.jscript.ScriptLogger class to DEBUG. Corresponding line of WEB-INF/classes/log4j.properties file is presented below:

log4j.logger.org.alfresco.repo.jscript.ScriptLogger=DEBUG

Then you can use the following command in your JavaScript to log the messages:

 logger.log("Log me");

Alfresco/Share Debuger

You can also activate server side JavasScript debugger to assist your development. To do so use the following links and enable debugger there:

  • Share: share/service/api/javascript/debugger
  • Alfresco: alfresco/service/api/javascript/debugger

Make sure that that the following lines is set to “on” in WEB-INF/classes/log4j.properties

log4j.logger.org.springframework.extensions.webscripts.ScriptDebugger=ON
log4j.logger.org.alfresco.repo.web.scripts.AlfrescoRhinoScriptDebugger=ON