šŸ“¬ blog.addEventListener()? Sign me up | No, thanks

Debugging an AEM App


Does your AEM App get stuck at a blank screen when you run it via the Cordova CLI?

Failure to initialize

The following steps will help you get to the root of the error on both iOS and Android.

iOS

These steps assume you have a functional Cordova build toolchain (including Xcode and the iOS Simulator), and are able to run cordova platform add ios && cordova emulate ios without any CLI related errors.

Enable Develop menu in Safari

From Safariā€™s menu, open ā€œPreferencesā€¦ā€, and navigate to the ā€œAdvancedā€ tab.

Make sure the checkbox labeled ā€œShow develop menu in menu barā€ is checked:

Develop mode checkbox

Connect the web inspector to your broken app

From the freshly enabled Develop menu, initiate a connection to your app running on the iOS Simulator (Iā€™ll be using the kitchen-sink app for this post):

Develop mode checkbox

You will be greeted by a new Web Inspector Safari window that is connected to the AEM App running on your iOS Simulator.

Refresh to see initialization errors

Navigate to the Console tab. You shouldnā€™t see any errors, aside from perhaps Safari attempting to load source maps that have not been provided. In order to see any errors which occurred during the initialization of the app, you will need to refresh the app. Locate the ā€˜Reload pageā€™ button and give it a click (or: hit āŒ˜ + R on your keyboard):

Reload app

You should now see a few lines of debug logging, along with an error!

Console output

In my case it appears that the ContentSync variable is missing. This variable is exported by the PhoneGap ContentSync plugin, so I would begin my bug investigation by seeing if this plugin has been successfully installed.

If this issue is occurring on an app obtained from an open source repo, the console output is extremely valuable and should be included in your bug report.

Android

Like above, ensure that you are able to run cordova platform add android && cordova emulate android without any CLI related errors before continuing.

Connect Chromeā€™s web inspector to the app

In Chrome, navigate to chrome://inspect, and locate your appā€™s WebView. Click the blue ā€œinspectā€ link to open the remote web inspector connected to your Android emulator.

Chrome inspect

Refresh to view initialization errors

Open the console tab and hit āŒ˜ + R on OS X, or Ctrl + R on Windows to refresh the current page of the application. In the screenshot below, I donā€™t have any errors in the console but I can still view the output of console.log statements in my code, such as navigation between pages:

Remote app Web Inspector console

Happy debugging!