///////////////////////// FOR BASE / ALL ////////////////////////////////////////////////// window.onerror = function(message, url, lineNumber) { // not helpful in production because main.js is called by subdomain > error is always just generic > not passed to server. // still here because can be helpful in dev, sends line number and error function is_cmt_script(url){ if (url.indexOf(".js") < 0){ return false; } js_scripts = ["aback.js","ajs_cookbook.js","ajs_cookbook_cover.js","ajs_cookbook_pdf.js","main.js","mp.js","sl.js","third_party_libs.js","third_party_libs_for_cb.js","main_tinetest.js",]; var arrayLength = js_scripts.length; for (var i = 0; i < arrayLength; i++) { var script = js_scripts[i]; if (url.indexOf(script) >= 0) { return true; } } return false; } msg_base_version = ""; // used to include js version. error_msg = "".concat(msg_base_version).concat(message).concat(" ").concat(lineNumber) + " " + url; if ( (message == "Script error." || message == "Script error") && lineNumber == "0"){ // third party domain js return true; } if (! is_cmt_script(url)){ return true; // so many other non-cmt errors from other extensions, browser. May be relevant sometimes, but just too many. // Will miss script in html, and js not loading errors } do_send_js_err_to_server(error_msg); return true; }; function do_send_js_err_to_server(error_msg){ var ua = navigator.userAgent.toLowerCase(); if ( ua.indexOf('googlebot') !=-1 ){ // googlebot gets weird errors because it sometimes uses old HTML with new JS. Ignore them return; } if (ua.indexOf("mozilla/5.0 (compatible; msie 9.0") !=-1 && user_id == 0){ // seems to be a bot, weird errors, never a user return; } error_msg = "js error: " + error_msg; $.ajax({ type: "POST", url: domain+"/error_in_js/", data: {"error_msg":error_msg,"csrfmiddlewaretoken":$('#csrf_token input').val(), "random":Math.floor(Math.random()*1000000)}, success: function(data){ } ,error: function() { } }); } function send_js_err_to_server(e){ if (domain.search("localhost") != -1 ){ var err = e; alert(g_current_url_and_request + " " + last_page_load_function + " " + e); throw new Error(err); // this way, icnludes line number. However, doesn't work with prod } else{ var err = g_current_url_and_request + " " + last_page_load_function + " " + e; do_send_js_err_to_server(err); } } $("#app").on('touchstart',function() { handle_hibernation_on_touch(); }); $("body").on("keypress","[role=button],[role=checkbox],[role=radio]", function(e) { // emulate