Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evangalen/5890424 to your computer and use it in GitHub Desktop.
Save evangalen/5890424 to your computer and use it in GitHub Desktop.
window.onerror = function(errorMsg, url, lineNumber) {
var text = document.documentElement.innerHTML;
var lines = text.match(/^.*((\r\n|\n|\r)|$)/gm);
var windowOnLoadLineNumber = null;
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
if (line.indexOf('window.onload') === 0) {
windowOnLoadLineNumber = i + 3;
break;
}
}
var actualLineNumber = lineNumber;
if (windowOnLoadLineNumber) {
actualLineNumber -= windowOnLoadLineNumber;
}
console.error('' + actualLineNumber + ': ' + errorMsg);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment