Skip to content

add stack and column number if available + make request asynch and remove deprecated ActiveX #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 31, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 12 additions & 13 deletions django_js_error_hook/templates/django_js_error_hook/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,9 @@
return null;
}
function logError(details) {
var xhr;
try {
xhr = new ActiveXObject('Msxml2.XMLHTTP');
} catch (e1) {
try {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
} catch (e2) {
xhr = new XMLHttpRequest();
}
}
xhr.open("POST", "{% url 'js-error-handler' %}", false);
var xhr = new XMLHttpRequest();

xhr.open("POST", "{% url 'js-error-handler' %}", true);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
var cookie = getCookie('csrftoken');
if (cookie) {
Expand All @@ -36,7 +28,14 @@
xhr.send(query.join('&'));
}

window.onerror = function(error_msg, url, line_number) {
logError(url + ':' + line_number + ': ' + error_msg);
window.onerror = function(msg, url, line_number, column_number, error_obj) {
var log_message = url + ': ' + line_number + ': ' + msg;
if (column_number) {
log_message += ", " + column_number;
}
if (error_obj && error_obj.stack) {
log_message += ", " + error_obj.stack;
}
logError(log_message);
};
})();