Skip to content
Tutorial

Debugging JavaScript on Android: Breakpoints, Stepping and the Call Stack

Debug Node.js code on your Android phone: breakpoints, conditions and logpoints, stepping, variables, the call stack and Hot Reload — and what it does not do yet.

Updated:
3 min
By Pelayo Naredo

Debugging JavaScript on Android: Breakpoints, Stepping and the Call Stack

PocketCode includes a debugger that works directly on your Android device, right next to the code you're running. This post says exactly what it does today — and what it doesn't.

Real debugging for Node.js

Open a JavaScript file (.js, .mjs, .cjs or .jsx) and choose Debug (Shift + F5 with a physical keyboard). PocketCode starts Node.js with its inspector and connects to it through the Chrome DevTools Protocol, so everything below runs against a real Node process on your phone:

  • Pause — the program stops on its first line, at your breakpoints, and when an exception is thrown that nothing catches
  • Continue, Step Over / Into / Out — move through the code one line, one call or one return at a time
  • Pause, Restart, Stop — control the session directly; Restart launches the file again under the debugger
  • Variables — a flat list of the local values of the top frame (objects are not expandable, and other frames' variables are not shown)
  • Call stack — the chain of frames that led to the current point; picking another frame only moves you to its line
  • Console — session events alongside your program's own output

Breakpoints, conditions and logpoints

Tap a line number to set a breakpoint: a red dot appears in the gutter, and tapping again removes it. When the program stops there, that line is highlighted. The Breakpoints tab of the debug panel lists them all; you can switch each one off (hollow dot) or edit it with the pencil:

  • Condition — a JavaScript expression such as i > 10; the program only pauses when it is true
  • Log message — turns the breakpoint into a logpoint: instead of pausing, it writes a line to the console. Put expressions in braces to print values: user = {user.name}, total = {total}. With a condition too, it logs only when the condition holds

Breakpoints you add, remove or edit while the program runs take effect straight away, without restarting.

Hot Reload

Turn on Hot Reload (the button in the debug toolbar, which only shows while a session is running; it is off by default) and every time you save a file of the project, the session restarts with the new code — no need to stop and debug again.

Other languages

The debugger is for JavaScript on Node.js only. For any other file, including TypeScript, Debug just runs it and prints that it has no debugger support; breakpoints do nothing. There is no step debugger for Python, Java or the other languages — for those, print values to the console and read the output.

An honest note on scope

These aren't there yet, so we won't advertise them as if they were:

  • Attaching to a remote host over the network and performance profiling
  • Evaluating an expression: the console has an "Evaluate expression" field, but it always answers undefined
  • Exception breakpoints: the debugger pauses on uncaught exceptions automatically, but you cannot add your own
  • Breakpoints stay on their line number: if you insert lines above one, it does not move with the code, and they are not kept when you close the app
  • Stop detaches the debugger; the process itself belongs to the Run panel

Breakpoints, logpoints, stepping and variables all run against real Node on your phone today.

PocketCode is heading to Google Play. Join the pre-registration to be among the first to try it on your own device.