I had a similar problem and my solution was ...
function myErrorFunction(message, url, linenumber) {
$.post(
"https://host.and/path/to/script/that/stores/entries",
{
"url":url,
"lineNumber":linenumber,
"message":message
},
function(){
if(console)
if(console.log)
console.log("Error reported.");
}
);
}
window.onerror = myErrorFunction;
To get a more sophisticated approach, you will need to use some of the tricks I put into my debugging project:
https://github.com/luke80/JavaScript-DebugTools-Luke
EDIT: Well, I will collect from this project the important bits that are relevant to your problem:
if(typeof String['hashCode'] == "undefined") {
String.prototype.hashCode = function(){
var hash = 0, i, char;
if (this.length == 0) return hash;
for (i = 0, l = this.length; i < l; i++) {
char = this.charCodeAt(i);
hash = ((hash<<5)-hash)+char;
hash |= 0;
}
return hash;
};
var _LOG_CALLERARGS_ON = true,
getCallerHash = function(funcString) {
return callerFunc.toString().hashCode();
},
getCallerArgs = function(obj) {
return JSON.stringify(Array.prototype.slice.call(obj),this._detectCircularity(Array.prototype.slice.call(obj))).replace(/^\[/,"(").replace(/\]$/,")");
},
detectCircularity = function(obj) {
return (function() {
var i = 0;
return function(key, value) {
if(i !== 0 && typeof(obj) === 'object' && typeof(value) == 'object' && obj == value) return '[Circular]';
if(i >= 29) return '[Too deep, not mined]';
++i;
return value;
}
})(detectCircularity);
},
caller = this.o.caller || arguments.callee.caller || "top";
if(typeof caller != "string") {
if(caller) {
var callerData = ((caller.name)?caller.name:"Unnamed Caller:"+getCallerHash(caller))+((_LOG_CALLERARGS_ON)?getCallerArgs(caller.arguments):"");
var maxLoops = 64;
var loopCounter = 0;
while(caller.caller && loopCounter < maxLoops) {
callerData += " <- "+((caller.caller.name)?caller.caller.name:"Unnamed Caller:"+getCallerHash(caller.caller))+((_LOG_CALLERARGS_ON)?getCallerArgs(caller.caller.arguments):"")
caller = caller.caller;
loopCounter++;
}
} else {
}
}
callerData ( , ), , .
, ( ), - ..
. , , . , .:)
, .