Skip to Navigation or
Skip to Content

JavaScript Console

The JavaScript Console project is a stand-alone JavaScript project that adds a console to the web page if one doesn't exist. It doesn't entirely replace tools like Firebug, but it acts like a supply-teacher for when the usual teacher isn't available. For this reason, I've called it SupplyConsole.

You can view a demo of SupplyConsole, you will notice the console gets added to the bottom of the page. It supports almost all of the normal console methods, such as log, error, assert, warn and so on. I will be adding support for some of the missing calls later - but even these will simply log a "not implemented" message, rather than blowing up.

Additionally you can get line numbers (depending on the browser) and stack trace (depending on the browser), with the addition of the Stack Trace project by Ric Wendelin, Luke Smith, Loic Dachary, Johan Euphrosine and Øyvind Sean Kinsey. This adds some richness to the console.trace() call.

To use the console, you need the following...

You then reference these scripts on the page you want the SupplyConsole to run on.

<script type="text/javascript" src="stacktrace-0.3.js"></script>
<script type="text/javascript" src="SupplyConsole.js"></script>

After these scripts, any console calls you make will be logged either to your active console, or by the SupplyConsole in an HTML panel at the bottom of the page.

If you aren't using the stacktrace.js project, you need to add the following line to the top of your script...

console.stackTrace = false;

Here are some examples of using the console...

console.time("Tests");
console.debug("Assert should pass");
console.assert(5 === 5);
console.debug("Info should log");
console.info("Write some info to the console");
console.debug("Log should log");
console.log("Write a log to the console");
console.debug("Stack trace should log if enabled");
console.trace("Trace");
console.debug("Warning should log");
console.warn("Write a warning to the console");
console.debug("Timer should display result");
console.timeEnd("Tests");

 

You Are Here: Home » JavaScript » JavaScript Console

 

I use a cookie on this website. This cookie doesn't contain or relate to any personal information and it isn't shared with any other website, it just ensures that I don't count you more than once in my website statistics. The Privacy and Electronic Communications Regulations require me to ask your permission to use this cookie, so please indicate below that you are happy for me to do this - I will remember your selection with a cookie, so if you accept I won't ask again...