Last active
December 16, 2015 22:39
-
-
Save yoeran/5508334 to your computer and use it in GitHub Desktop.
Javascript error tracking module
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Package : nl.yoeran.reporter | |
Date : 03-05-2013 | |
Author : Yoeran Luteijn <[email protected]> | |
Description : Little script to track frontend errors. No external library needed. | |
Template : https://gist.github.com/4078993 | |
*/ | |
define(function(){ | |
function Reporter() | |
{ | |
/* Private */ | |
var self = this, | |
$host = '', | |
$count = 0; | |
function logError(errorMsg, url, lineNumber) | |
{ | |
$count++; | |
var base = url.split('/'); | |
base = 'http://' + base[2] + '/'; | |
// get all js files | |
var js = []; | |
var s = document.getElementsByTagName('script'); | |
for(var i in s ){ if( s[i].src ){ | |
js.push( s[i].src.replace(base,'') ); | |
} } | |
// setup params | |
var p = [ | |
'?log=' + $count, | |
'desc=' + escape(errorMsg), | |
'file=' + escape(url), | |
'line=' + escape(lineNumber), | |
'url=' + escape(document.location.href), | |
'js_files=' + escape( js.join(',') ) | |
]; | |
// send error to designated URL | |
new Image().src = $host + p.join('&'); | |
} | |
/* Public */ | |
self.init = function( url ) | |
{ | |
$host = url; | |
window.onerror = function(m,u,l){ | |
logError(m,u,l); | |
} | |
} | |
return( self ); | |
}// end Reporter | |
return( Reporter() ); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment