(function () { //If user has not already defined the errlog callback func, let's make it a dev/null if (typeof _errlog_callback === 'undefined') { _errlog_callback = function () { }; } function Packet(/*required*/ apikey, /*required*/ error, /*required*/ trace, /*required*/ method, errortype, customdata) { //Take arguments in order of preference? this.apikey = apikey; this.errordate = (new Date()); var qs = window.location.href; qs = qs.substr(qs.indexOf('?')+1); this.querystring = qs; this.useragent = window.navigator.userAgent; this.lineno = error.lineno; this.colno = error.colno; this.filename = error.filename; this.message = error.message; this.type = (typeof errortype == 'errorunknown' ? null: errortype); this.trace = trace; this.applicationname = ErrLog.settings.application_name; this.page = window.location.href.split('?')[0]; this.browsername = window.navigator.appName; //For JS - look at the code Mike put together and see if it's there. - should include the version number too. this.assemblyversion = window.navigator.appVersion; this.method = method; //Error site this.servername = window.location.host; //server name where log came from (domain for JS?) this.browser_capabilities = ''; //null for js - derived in C# etc. this.session_data = {}; //Can't get this for JS - but cookies? this.application_data = ''; //Don't know what this will do for JS - undefined? this.request_header = ''; //Nonsense for JS this.request_formdata = getformdata(); //see card for JS relevant stuffs this.request_cookies = getcookies(); this.custom = (typeof customdata == 'undefined' ? null: customdata); //JSON string for cool kids. this.environment = { navigator: getnavdata(), screen: getscreendata(), location:window.location}; //Undefined for JS - usually CPU/RAM, et al. this.languageid = 2; //is enum from cool server stuff that doesn't exist yet. JS is 2. this.packageversion = 'js.v1'; } function getformdata() { var formsdata = []; for(var key in window.document.forms) { //console.log(key, window.document.forms); var frm = window.document.forms[key]; var currentdata = []; for(var i=0; i0) { fakeStackString = fakeStackStringList.join("\n"); error.message += "\n```\n" + fakeStackString; } } var trace = "No stack trace available!"; var method = "unknown"; try { method = e.message; } catch (errdontcare) {} var errorType = error_type || "errorunknown"; if (e.error) { if (e.error.trace || typeof e.error.stack != "undefined") { trace = JSON.stringify(e.error.stack); errorType = error_type || "error"; //We would like to know the method name that had the issue, so let's try: if (e.error.stack.split('\n').length > 0) { var it = e.error.stack.split('\n').pop(); if (it.indexOf('at ') >= 0) { it = it.split('at ')[1]; if(it.indexOf('('>=0 && it.indexOf(')')>=0)) { //This is probably listing the error with a filename and line number etc, like: // at HTMLElement. ("http://some.place/filename:10:10") it = it.split(" (")[0]; } if (it.indexOf(':') >= 0) { it = it.split(':')[0]; } } if (it.length > 0) { method = it; } } } } var apikey = "1E6B20B4-5BB3-4140-B83D-86CE0796A532"; var post = new Packet(apikey, error, trace, method, errorType, custom_json); //Clean up all the post data, making sure we remove anything that exists in 'keys_to_exclude' if(ErrLog.settings.key_check) { for(var i=0; i-1) { post.session_data[n].value = '[REDACTED]'; } } } } post.page = valordefault(pagename, post.page); //respect the settings.application_name or the application_name passed into this call. post.applicationname = valordefault(application_name, post.applicationname); //Adhere to the `exclude_completely` setting var x = new XMLHttpRequest(); var logurl = "https://relay.errlog.io/logcap"; // if (true) logurl = "devrelay.errlog.io/logcap"; x.open("POST", logurl, true); x.setRequestHeader('Content-Type', 'application/json'); x.onreadystatechange = function () { if (this.readyState == 4 && this.status == 200) _errlog_callback(this.responseText); }; x.send(packdata(post)); } function packdata(jsonobj) { return JSON.stringify(jsonobj); } window.ErrLog = { settings: { application_name: window.location.hostname, key_check: true, keys_to_exclude: ['password', 'pwd', 'token', 'key', 'viewstate', 'aspnet', 'validation'], exclude_completely: false, language_id: 2, exclude_cookies: false }, logger: { log: logerrpost } }; if(typeof window.ErrLogSettings !== 'undefined') { //Allow the user to specify settings before the script include, such that their settings are loaded in and used. for(var key in ErrLogSettings) { if(key == 'keys_to_exclude' && Array.isArray(ErrLogSettings[key])) ErrLog.settings[key] = ErrLog.settings[key].concat(ErrLogSettings[key]); //Concat the array, and stuff. if(typeof ErrLog.settings[key] !== 'undefined') ErrLog.settings[key] = ErrLogSettings[key]; } } //Enable errlog on global error listener window.addEventListener('error', logerrpost); })()