omorandi / TiInspector

Debug Titanium Mobile applications through Chrome DevTools
MIT License
108 stars 14 forks source link

Ti Inspector

Ti Inspector allows debugging Appcelerator Titanium applications in the Chrome DevTools web interface.

The tool acts as a gateway by translating commands and messages between the Chrome DevTools Debugging Protocol and the Titanium Debugger Protocol (and vice-versa).

Currently only the iOS target platform is supported.

Motivation

Since my Titanium development workflow mainly revolves around Sublime Text and the CLI, and firing up Titanium Studio for tracking down bugs in the integrated debugger is most of the time a painfully slow activity (start the IDE, rebuild for debugging, etc.), I wanted a more agile way to fire up a JavaScript debug session. Moreover, when debugging native modules in Xcode, sometimes it would be nice to have a view on both sides (JS and native) of the code.

You can find a more detailed post and a short demo here

NOTE - Titanium SDK 3.5.X

Currently Ti Inspector doesn't work correctly with Ti SDK 3.5.X. Since the 3.5.0 release, Titanium underwent major changes regarding the JavaScriptCore engine and its debugger library (libti_ios_debugger.a). In particular, the currently known issues are:

The former is also seen in the Ti Studio debugger. Follow and watch https://jira.appcelerator.org/browse/TIMOB-18616 for additional info.

While these issues are being worked on, as a temporary solution, Ti Inspector can be used by building the app with Ti SDK 3.4.1.GA during debugging

Install

For running Ti Inspector a working node.js setup is required.

The Ti Inspector module can be installed through npm with

    $ [sudo] npm install -g ti-inspector

Dev install

In alternative, if you like to stay on the edge, you can pull the code from github and use npm link:

  $ git clone git@github.com:omorandi/TiInspector.git
  $ cd TiInspector
  $ npm install
  $ [sudo] npm link

Using Ti Inspector

The ti-inspector script can be invoked from the command line with the following arguments:

    ti-inspector [Options] [TiProjectDir]

    options:
       --web-host=[host]      host for the inspector server (default localhost)
       --web-port=[port]      port for the inspector server (default 8080)
       --debugger-port=[port] port for the Titanium debug server (default 8999)

    TiProjectDir:
       Directory containing a Titanium app project.
       If not specified, the current directory is used.

Supposing you have a terminal open on a directory containing the Titanium project you want to debug you can simply issue:

    $ ti-inspector

which runs the script with the default argument values, then point the browser to http://localhost:8080 where a web page for the current project is shown, telling that no active debugging session is present.

In order to start the Titanium application for debugging it, you have to use the Titanium CLI build command, using the --debug-host hidden option. For example:

    $ titanium build -p iphone --debug-host localhost:8999

The --debug-host argument represents the host:port pair where the debug server is listening. This is normally provided by Titanium Studio when the project is started in debug mode, however in our case Ti Inspector will act as a debug server (listening by default on tcp port 8999) for the running app.

Once the app is running in the iOS Simulator, only the splash screen will be visible, while in the page previously opened in the browser will list the current debug session:

By clicking on it, the DevTools page will be open, showing the app.js file source code.

From there on, you can debug your application by setting breakpoints, stepping through code, watching variables, or evaluating expressions in the console panel, etc.

Features

Limitations

Themes FTW (available from V. 0.0.3) - NOTE: NOT WORKING SINCE v0.1.2

The DevTools app styling can be customized quite easily and some open source custom css are available from http://devthemez.com/themes/chrome-developer-tools. These can also be used with Ti Inspector, which already includes some in the public/themes/ directory.

Adding a custom Theme

If you don't like the already available themes, you can download one from http://devthemez.com/themes/chrome-developer-tools, then:

Changelog

0.1.2

0.1.1

0.1.0

0.0.5

0.0.4

0.0.3

Credits

Ti Inspector was originally inspired by node-inspector, started by (Danny Coates)[https://github.com/dannycoates]

License

See LICENSE file