Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Javascript utility to track and report errors in pages
Python JavaScript

This branch is 21 commits ahead, 78 commits behind Offbeatmammal:master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
src
README.markdown

README.markdown

Readme for jsErrLog

What is this?

jsErrLog is a simple JavaScript script that catches your in-browser JavaScript errors and posts them to the jsErrLog Service. This enables you to always be on top of your JavaScript errors.

jsErrLog Service: http://jserrlog.appspot.com

How to use

Insert

<script type="text/javascript" src="jserrlog.js"></script>

directly after your browsers tag. You may optionally, directly after the script tag add additional parameters to the error report handling:

<script type="text/javascript">
    // Configure site parameters
    //jsErrLog.debugMode = true;
    // Optionally add additional debug information to the jsErrLog.info
    // message field
    //jsErrLog.info = "Populated the Info Message to pass to logger"
    // Optionally specify URL to which the logging should be done
    //jsErrLog.url = "http://www.myservice.com/logger.js";
</script>

The options are:

  • jsErrLog.debugMode: Set to true if you'd like the web browser not to swallow in-browser errors.
  • jsErrLog.info: A custom string bundled with the HTTP GET request. Can be used to add additional information, such as a customer number, extra state or similar.
  • jsErrLog.url: The absolute URL to which GET requests will be made. See below for more information on how to do this. If not specified, the jsErrLog.url will default to

    http://jserrlog.appspot.com/logger.js

Which web browsers does this script support?

  • IE 6.0 and above
  • Firefox 3.6.22 and above
  • Chrome 10 and above (including ChromeOS)
  • Safari 5.1 and above / WebKit nightlies (thought this error needs resolving.)

Un-supported browsers at this time

  • Opera
  • Android

Additional information

Original blog posts are available here

If your browser is not in the list above, please consider opening up the jsErrLog demo page (src/demo/index.html) to help us verify whether the script works in your browser or not.

How to point jsErrLog to your own service

There are a couple of cases when you might want to host your own jsErrLog server that receives all the errors on your site:

  • You are worried about security. This includes:
    • That user credentials might get passed to the appspot service and be publicly available for others to view as long as they know your full domain URL.
    • That the response JavaScript file in the future might contain malicious code that enables cross site scripting attacks (XSS).
  • You would like to have the errors e-mailed to you directly.
  • You would like to incorporate the error messages into your existing company workflow. Two examples are
    • Sending out an e-mail to one or multiple people about the error.
    • Adding the JavaScript to some ticketing system.
  • You are on an Intranet that blocks communication out to the WWW.

To roll your own jsErrLog service there are two things you need to do:

  1. Override the default URL that the jsErrLog browser script should use.
  2. Implement your server side engine to handle the requests coming in from browsers.

Overriding the default URL

This one is easy. Just set the jsErrLog.url to something similar to the URL of your error logger. A full example here below:

<script type="text/javascript" src="jserrlog.js"></script>
<script type="text/javascript">
    jsErrLog.url = "http://www.myownservice.com/logger.js";
</script>

note that it is recommended for the URL to end with '.js'. Also note that it must support HTTP GET requests.

Implementing your own logging service

For every client side (in-browser) JavaScript error, an HTTP GET request is is being made to the URL you specified. Every request contains the following parameters:

The response given by your service must be valid JavaScript. This is very important, as it otherwise might lead to a flood of requests coming in as one JavaScript yields another one (and each one a new request).

Generally it is good to clean up in the client's DOM. This is done by adding the following line in your response body:

jsErrLog.removeScript(<?=$_GET['i']?>);

where <?=$_GET['i']?> (which is PHP) can be substituted with your language specific way of extracting the value of the GET parameter i.

You may also add additional JavaScript in your response if you want to. You could for example show a simple alert(…) box telling the user that the error has been logged and that you are looking into it. However, do note that the alert box might pop up multiple times being both annoying and/or making the browser unusable if stuck in a bad loop. Another option would be to have a 'soft popup' show up in the client's web interface.

Also, note that not all JavaScript errors will always be errors that the user will notice. Maybe he/she will never click on the button that would trigger the broken callback function etcetera.

Contribute

This project can be forked on Github. Please issue pull requests from feature branches.

Something went wrong with that request. Please try again.