Skip to content

Using the console API

paulbartrum edited this page Dec 14, 2015 · 2 revisions

The Firebug console API allows javascript programs to write to the console (along with a few other tricks). It is available for use, but is disabled by default. To enable it, use the following code:

var engine = new Jurassic.ScriptEngine();
engine.SetGlobalValue("console", new Jurassic.Library.FirebugConsole(engine));

Here's an example of using the console object within JavaScript:

var x = 15, y = 'test';
console.log('X is %i, Y is %s', x, y);

This prints "X is 15, Y is test" to the console.

Only a subset of the functionality of the Firebug console API is available at this time. The available functions are:

  • log
  • debug
  • info
  • warn
  • error
  • assert
  • group
  • groupEnd
  • time
  • timeEnd

In addition, only the following format string specifiers are supported:

Specifier Type
%s string
%d integer
%i integer
%f floating point number

Next tutorial: Calling a single .NET method from JavaScript