Skip to content

Framework-agnostic, micro-library for getting stack traces in all web browsers

License

Notifications You must be signed in to change notification settings

hhart/javascript-stacktrace

Repository files navigation

What is stacktrace.js?

A Javascript tool that allows you to debug your JavaScript by giving you a stack trace of function calls leading to an error (or any condition you specify)

How do I use stacktrace.js?

Just include stacktrace.js file on your page, and call it like so:

<scripttype="text/javascript" src="path/to/stacktrace.js" /><scripttype="text/javascript"> ... yourcode...if(errorCondition){vartrace=printStackTrace();//Output however you want!alert(trace.join('\n\n'));} ... morecodeofyours...</script>

Bookmarklet available on the project home page.

You can also pass in your own Error to get a stacktrace not available in IE or Safari 5-

varlastError;try{// error producing code}catch(e){lastError=e;// do something else with error}// Returns stacktrace from lastError!printStackTrace({e: lastError});

Function Instrumentation

You can now have any (public or privileged) function give you a stacktrace when it is called:

varp=newprintStackTrace.implementation();p.instrumentFunction(this,'baz',logStackTrace);functionlogStackTrace(stack){console.log(stack.join('\n'));}functionfoo(){vara=1;bar();}functionbar(){baz();}foo();//Will log a stacktrace when 'baz()' is called containing 'foo()'!p.deinstrumentFunction(this,'baz');//Remove function instrumentation

What browsers does stacktrace.js support?

It is currently tested and working on:

  • Firefox (and Iceweasel) 0.9+
  • Google Chrome 1+
  • Safari 3.0+ (including iOS 1+)
  • Opera 7+
  • IE 5.5+
  • Konqueror 3.5+
  • Flock 1.0+
  • SeaMonkey 1.0+
  • K-Meleon 1.5.3+
  • Epiphany 2.28.0+
  • Iceape 1.1+

Contributions

This project is made possible due to the efforts of these fine people:

About

Framework-agnostic, micro-library for getting stack traces in all web browsers

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published