-
Notifications
You must be signed in to change notification settings - Fork 8
/
appenlight-client.min.js
3 lines (2 loc) · 12.8 KB
/
appenlight-client.min.js
1
2
3
/*! appenlight-client 04-04-2017 */
!function(a){"use strict";function b(a){a=Object(a);for(var b=1;b<arguments.length;b++){var c=arguments[b];if(c)for(var e in c)d(c,e)&&(a[e]=c[e])}return a}function c(a){if(a){for(var b=new Array(a.length+1),c=0;c<a.length;c++)try{var d=a[c];d.length>300?b[c]="<minified-context>":b[c]=d}catch(a){b[c]="<error-parsing-context>"}return b[c]="",b.join("\n")}return""}function d(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function e(a){var b=[];for(var c in a)d(a,c)&&b.push([c,a[c]]);return b}for(var f=["debug","info","warning","error","critical"],g={version:"0.5.1",options:{apiKey:"undefined",protocolVersion:"0.5",sendInterval:1e3,server:"https://api.appenlight.com",tracekitContextLines:11,tracekitRemoteFetching:!0,windowOnError:!1},errorReportBuffer:[],slowReportBuffer:[],logBuffer:[],requestInfo:{},extraInfo:{},tags:{},init:function(a){var c=this;b(this.options,a),this.options.sendInterval>=1e3&&this.createSendInterval(this.options.sendInterval),this.reportsEndpoint=this.options.server+"/api/reports?public_api_key="+this.options.apiKey+"&protocolVersion="+this.options.protocolVersion,this.logsEndpoint=this.options.server+"/api/logs?public_api_key="+this.options.apiKey+"&protocolVersion="+this.options.protocolVersion,TraceKit.collectWindowErrors=this.options.windowOnError,TraceKit.remoteFetching=this.options.tracekitRemoteFetching,TraceKit.linesOfContext=this.options.tracekitContextLines,TraceKit.report.subscribe(function(a){c.handleError(a)})},createSendInterval:function(a){var b=this;this.sendIv=setInterval(function(){b.sendReports(),b.sendLogs()},a)},clearRequestInfo:function(){this.requestInfo={}},setRequestInfo:function(a){b(this.requestInfo,a)},clearGlobalExtra:function(a){if(a)for(var b=0;b<a.length;b++)delete this.extraInfo[a[b]];else this.extraInfo={}},addGlobalExtra:function(a){b(this.extraInfo,a)},clearGlobalTags:function(a){if(a)for(var b=0;b<a.length;b++)delete this.tags[a[b]];else this.tags={}},addGlobalTags:function(a){b(this.tags,a)},clearGlobalNamespace:function(){this.options.namespace=void 0},setGlobalNamespace:function(a){this.options.namespace=a},grabError:function(a,b){try{var c=TraceKit.computeStackTrace(a);this.handleError(c,b)}catch(b){if(a!==b)throw b}},handleError:function(d,f){f=f||{};var g="";g="stack"===d.mode?d.name+": "+d.message:d.message;var h={client:"javascript",language:"javascript",error:g,occurences:1,priority:5,server:"",http_status:500,request:{},traceback:[],extra:e(b({},this.extraInfo,f.extra)),tags:e(b({},this.tags,f.tags)),url:a.location.href};h.user_agent=a.navigator.userAgent,h.start_time=(new Date).toJSON(),b(h,this.requestInfo),h.request_id||(h.request_id=this.genUUID4());for(var i=d.stack.reverse().slice(-100),j=0;j<i.length;j++){var k="",l=i[j];try{void 0!==l.context&&(k=c(l.context),j===i.length-1&&(k+="\n"+g))}catch(a){}var m={cline:k,file:l.url,fn:l.func,line:l.line,vars:[]};h.traceback.push(m)}this.errorReportBuffer.push(h)},log:function(c,d,f,g,h){void 0===f&&(f=void 0!==this.options.namespace?this.options.namespace:a.location.pathname),void 0===g&&(g=null);var i={log_level:c.toUpperCase(),message:d,date:(new Date).toJSON(),namespace:f,request_id:g,tags:e(b({},this.tags,h))};this.requestInfo&&void 0!==this.requestInfo.server&&(i.server=this.requestInfo.server),this.logBuffer.push(i)},genUUID4:function(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(a){var b=16*Math.random()|0;return("x"===a?b:3&b|8).toString(16)})},sendReports:function(){if(this.errorReportBuffer.length<1)return!0;var a=this.errorReportBuffer;return this.submitData(this.reportsEndpoint,a),this.errorReportBuffer=[],!0},sendLogs:function(){if(this.logBuffer.length<1)return!0;var a=this.logBuffer;return this.submitData(this.logsEndpoint,a),this.logBuffer=[],!0},submitData:function(b,c){var d=new a.XMLHttpRequest;!d&&a.ActiveXObject&&(d=new a.ActiveXObject("Microsoft.XMLHTTP")),d.open("POST",b,!0),d.setRequestHeader("Content-Type","application/json"),d.send(JSON.stringify(c))}},h=0;h<f.length;h++){var i=f[h];g[i]=function(a){return function(){var b=[].slice.call(arguments);return b.unshift(a),this.log.apply(this,b)}}(i)}a.AppEnlight=g,"function"==typeof define&&define.amd&&define("appenlight",[],function(){return g})}(window),function(a,b){function c(a,b){return Object.prototype.hasOwnProperty.call(a,b)}function d(a){return void 0===a}if(a){var e={},f=a.TraceKit,g=[].slice,h="?";e.noConflict=function(){return a.TraceKit=f,e},e.wrap=function(a){function b(){try{return a.apply(this,arguments)}catch(a){throw e.report(a),a}}return b},e.report=function(){function b(a){i(),n.push(a)}function d(a){for(var b=n.length-1;b>=0;--b)n[b]===a&&n.splice(b,1)}function f(a,b){var d=null;if(!b||e.collectWindowErrors){for(var f in n)if(c(n,f))try{n[f].apply(null,[a].concat(g.call(arguments,2)))}catch(a){d=a}if(d)throw d}}function h(a,b,c,d,g){var h=null;if(q)e.computeStackTrace.augmentStackTraceWithInitialElement(q,b,c,a),j();else if(g)h=e.computeStackTrace(g),f(h,!0);else{var i={url:b,line:c,column:d};i.func=e.computeStackTrace.guessFunctionName(i.url,i.line),i.context=e.computeStackTrace.gatherContext(i.url,i.line),h={mode:"onerror",message:a,stack:[i]},f(h,!0)}return!!l&&l.apply(this,arguments)}function i(){!0!==m&&(l=a.onerror,a.onerror=h,m=!0)}function j(){var a=q,b=o;o=null,q=null,p=null,f.apply(null,[a,!1].concat(b))}function k(b){if(q){if(p===b)return;j()}var c=e.computeStackTrace(b);throw q=c,p=b,o=g.call(arguments,1),a.setTimeout(function(){p===b&&j()},c.incomplete?2e3:0),b}var l,m,n=[],o=null,p=null,q=null;return k.subscribe=b,k.unsubscribe=d,k}(),e.computeStackTrace=function(){function b(b){if(!e.remoteFetching)return"";try{var c=function(){try{return new a.XMLHttpRequest}catch(b){return new a.ActiveXObject("Microsoft.XMLHTTP")}}();return c.open("GET",b,!1),c.send(""),c.responseText}catch(a){return""}}function f(d){if("string"!=typeof d)return[];if(!c(w,d)){var e="",f="";try{f=a.document.domain}catch(a){}var g=/(.*)\:\/\/([^:\/]+)([:\d]*)\/{0,1}([\s\S]*)/.exec(d);g&&g[2]===f&&(e=b(d)),w[d]=e?e.split("\n"):[]}return w[d]}function g(a,b){var c,e=/function ([^(]*)\(([^)]*)\)/,g=/['"]?([0-9A-Za-z$_]+)['"]?\s*[:=]\s*(function|eval|new Function)/,i="",j=f(a);if(!j.length)return h;for(var k=0;k<10;++k)if(i=j[b-k]+i,!d(i)){if(c=g.exec(i))return c[1];if(c=e.exec(i))return c[1]}return h}function i(a,b){var c=f(a);if(!c.length)return null;var g=[],h=Math.floor(e.linesOfContext/2),i=h+e.linesOfContext%2,j=Math.max(0,b-h-1),k=Math.min(c.length,b+i-1);b-=1;for(var l=j;l<k;++l)d(c[l])||g.push(c[l]);return g.length>0?g:null}function j(a){return a.replace(/[\-\[\]{}()*+?.,\\\^$|#]/g,"\\$&")}function k(a){return j(a).replace("<","(?:<|<)").replace(">","(?:>|>)").replace("&","(?:&|&)").replace('"','(?:"|")').replace(/\s+/g,"\\s+")}function l(a,b){for(var c,d,e=0,g=b.length;e<g;++e)if((c=f(b[e])).length&&(c=c.join("\n"),d=a.exec(c)))return{url:b[e],line:c.substring(0,d.index).split("\n").length,column:d.index-c.lastIndexOf("\n",d.index)-1};return null}function m(a,b,c){var d,e=f(b),g=new RegExp("\\b"+j(a)+"\\b");return c-=1,e&&e.length>c&&(d=g.exec(e[c]))?d.index:null}function n(b){if(!d(a&&a.document)){for(var c,e,f,g,h=[a.location.href],i=a.document.getElementsByTagName("script"),m=""+b,n=/^function(?:\s+([\w$]+))?\s*\(([\w\s,]*)\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,o=/^function on([\w$]+)\s*\(event\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/,p=0;p<i.length;++p){var q=i[p];q.src&&h.push(q.src)}if(f=n.exec(m)){var r=f[1]?"\\s+"+f[1]:"",s=f[2].split(",").join("\\s*,\\s*");c=j(f[3]).replace(/;$/,";?"),e=new RegExp("function"+r+"\\s*\\(\\s*"+s+"\\s*\\)\\s*{\\s*"+c+"\\s*}")}else e=new RegExp(j(m).replace(/\s+/g,"\\s+"));if(g=l(e,h))return g;if(f=o.exec(m)){var t=f[1];if(c=k(f[2]),e=new RegExp("on"+t+"=[\\'\"]\\s*"+c+"\\s*[\\'\"]","i"),g=l(e,h[0]))return g;if(e=new RegExp(c),g=l(e,h))return g}return null}}function o(a){if(!a.stack)return null;for(var b,c,e=/^\s*at (.*?) ?\(((?:file|https?|blob|chrome-extension|native|webpack|eval).*?)(?::(\d+))?(?::(\d+))?\)?\s*$/i,f=/^\s*(.*?)(?:\((.*?)\))?(?:^|@)((?:file|https?|blob|chrome|webpack|\[native).*?)(?::(\d+))?(?::(\d+))?\s*$/i,j=/^\s*at (?:((?:\[object object\])?.+) )?\(?((?:ms-appx|https?|webpack|blob):.*?):(\d+)(?::(\d+))?\)?\s*$/i,k=a.stack.split("\n"),l=[],n=/^(.*) is undefined$/.exec(a.message),o=0,p=k.length;o<p;++o){if(b=e.exec(k[o])){var q=b[2]&&-1!==b[2].indexOf("native");c={url:q?null:b[2],func:b[1]||h,args:q?[b[2]]:[],line:b[3]?+b[3]:null,column:b[4]?+b[4]:null}}else if(b=j.exec(k[o]))c={url:b[2],func:b[1]||h,args:[],line:+b[3],column:b[4]?+b[4]:null};else{if(!(b=f.exec(k[o])))continue;c={url:b[3],func:b[1]||h,args:b[2]?b[2].split(","):[],line:b[4]?+b[4]:null,column:b[5]?+b[5]:null}}!c.func&&c.line&&(c.func=g(c.url,c.line)),c.line&&(c.context=i(c.url,c.line)),l.push(c)}return l.length?(l[0]&&l[0].line&&!l[0].column&&n?l[0].column=m(n[1],l[0].url,l[0].line):l[0].column||d(a.columnNumber)||(l[0].column=a.columnNumber+1),{mode:"stack",name:a.name,message:a.message,stack:l}):null}function p(a){var b=a.stacktrace;if(b){for(var c,d=/ line (\d+).*script (?:in )?(\S+)(?:: in function (\S+))?$/i,e=/ line (\d+), column (\d+)\s*(?:in (?:<anonymous function: ([^>]+)>|([^\)]+))\((.*)\))? in (.*):\s*$/i,f=b.split("\n"),h=[],j=0;j<f.length;j+=2){var k=null;if((c=d.exec(f[j]))?k={url:c[2],line:+c[1],column:null,func:c[3],args:[]}:(c=e.exec(f[j]))&&(k={url:c[6],line:+c[1],column:+c[2],func:c[3]||c[4],args:c[5]?c[5].split(","):[]}),k){if(!k.func&&k.line&&(k.func=g(k.url,k.line)),k.line)try{k.context=i(k.url,k.line)}catch(a){}k.context||(k.context=[f[j+1]]),h.push(k)}}return h.length?{mode:"stacktrace",name:a.name,message:a.message,stack:h}:null}}function q(b){var d=b.message.split("\n");if(d.length<4)return null;var e,h=/^\s*Line (\d+) of linked script ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,j=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?|blob)\S+)(?:: in function (\S+))?\s*$/i,m=/^\s*Line (\d+) of function script\s*$/i,n=[],o=a&&a.document&&a.document.getElementsByTagName("script"),p=[];for(var q in o)c(o,q)&&!o[q].src&&p.push(o[q]);for(var r=2;r<d.length;r+=2){var s=null;if(e=h.exec(d[r]))s={url:e[2],func:e[3],args:[],line:+e[1],column:null};else if(e=j.exec(d[r])){s={url:e[3],func:e[4],args:[],line:+e[1],column:null};var t=+e[1],u=p[e[2]-1];if(u){var v=f(s.url);if(v){v=v.join("\n");var w=v.indexOf(u.innerText);w>=0&&(s.line=t+v.substring(0,w).split("\n").length)}}}else if(e=m.exec(d[r])){var x=a.location.href.replace(/#.*$/,""),y=new RegExp(k(d[r+1])),z=l(y,[x]);s={url:x,func:"",args:[],line:z?z.line:e[1],column:null}}if(s){s.func||(s.func=g(s.url,s.line));var A=i(s.url,s.line),B=A?A[Math.floor(A.length/2)]:null;A&&B.replace(/^\s*/,"")===d[r+1].replace(/^\s*/,"")?s.context=A:s.context=[d[r+1]],n.push(s)}}return n.length?{mode:"multiline",name:b.name,message:d[0],stack:n}:null}function r(a,b,c,d){var e={url:b,line:c};if(e.url&&e.line){a.incomplete=!1,e.func||(e.func=g(e.url,e.line)),e.context||(e.context=i(e.url,e.line));var f=/ '([^']+)' /.exec(d);if(f&&(e.column=m(f[1],e.url,e.line)),a.stack.length>0&&a.stack[0].url===e.url){if(a.stack[0].line===e.line)return!1;if(!a.stack[0].line&&a.stack[0].func===e.func)return a.stack[0].line=e.line,a.stack[0].context=e.context,!1}return a.stack.unshift(e),a.partial=!0,!0}return a.incomplete=!0,!1}function s(a,b){for(var c,d,f,i=/function\s+([_$a-zA-Z\xA0-\uFFFF][_$a-zA-Z0-9\xA0-\uFFFF]*)?\s*\(/i,j=[],k={},l=!1,o=s.caller;o&&!l;o=o.caller)if(o!==t&&o!==e.report){if(d={url:null,func:h,args:[],line:null,column:null},o.name?d.func=o.name:(c=i.exec(o.toString()))&&(d.func=c[1]),void 0===d.func)try{d.func=c.input.substring(0,c.input.indexOf("{"))}catch(a){}if(f=n(o)){d.url=f.url,d.line=f.line,d.func===h&&(d.func=g(d.url,d.line));var p=/ '([^']+)' /.exec(a.message||a.description);p&&(d.column=m(p[1],f.url,f.line))}k[""+o]?l=!0:k[""+o]=!0,j.push(d)}b&&j.splice(0,b);var q={mode:"callers",name:a.name,message:a.message,stack:j};return r(q,a.sourceURL||a.fileName,a.line||a.lineNumber,a.message||a.description),q}function t(a,b){var c=null;b=null==b?0:+b;try{if(c=p(a))return c}catch(a){if(v)throw a}try{if(c=o(a))return c}catch(a){if(v)throw a}try{if(c=q(a))return c}catch(a){if(v)throw a}try{if(c=s(a,b+1))return c}catch(a){if(v)throw a}return{mode:"failed"}}function u(a){a=1+(null==a?0:+a);try{throw new Error}catch(b){return t(b,a+1)}}var v=!1,w={};return t.augmentStackTraceWithInitialElement=r,t.guessFunctionName=g,t.gatherContext=i,t.ofCaller=u,t.getSource=f,t}(),e.extendToAsynchronousCallbacks=function(){var b=function(b){var c=a[b];a[b]=function(){var a=g.call(arguments),b=a[0];return"function"==typeof b&&(a[0]=e.wrap(b)),c.apply?c.apply(this,a):c(a[0],a[1])}};b("setTimeout"),b("setInterval")},e.remoteFetching||(e.remoteFetching=!0),e.collectWindowErrors||(e.collectWindowErrors=!0),(!e.linesOfContext||e.linesOfContext<1)&&(e.linesOfContext=11),"undefined"!=typeof module&&module.exports&&a.module!==module?module.exports=e:"function"==typeof define&&define.amd?define("TraceKit",[],e):a.TraceKit=e}}("undefined"!=typeof window?window:global);