I am currently working on a web application, I have a JS logging mechanism that Handles Javascript error that are not caught by the js code inside the page. I am using window.onerror to catch all such errors and log them else where.
However, Problem is with Opera which does not have window.onerror event. one approach I could think of is, to string process all js functions code and insert try catch blocks inside those functions after body load. It does not work in many cases though, But, It at least works to some extent.
I am sure this approach sucks, But, I could not think of anything better. Please advise.
Update: For now, I am calling the code below to Catch as many errors as I could.
function OnBodyLoad()
{
var allElements = document.getElementsByTagName("*");
for(var cnt = 0;cnt < allElements.length;cnt++)
{
RegisterAllEvents(allElements[cnt]);
}
}
function RegisterAllEvents(objToProcess){
for(var cnt = 0;cnt < objToProcess.attributes.length;cnt++){
if(IsAttributeAnEvent(objToProcess.attributes[cnt].name))
{
objToProcess.attributes[cnt].value = 'try{'+objToProcess.attributes[cnt].value+'}catch(err){LogError("'+ objToProcess.id+'"'+ ',err);}';
}
}
}