dpaste/pastebin/static/raven-0.4.min.js
2012-06-16 00:07:11 +02:00

2 lines
No EOL
5.4 KiB
JavaScript

/* Raven.js v0.4 | https://github.com/lincolnloop/raven-js/ */
function parseUri(e){var d=parseUri.options,a=d.parser[d.strictMode?"strict":"loose"].exec(e),c={},b=14;while(b--){c[d.key[b]]=a[b]||""}c[d.q.name]={};c[d.key[12]].replace(d.q.parser,function(g,f,h){if(f){c[d.q.name][f]=h}});return c}parseUri.options={strictMode:false,key:["source","protocol","authority","userInfo","user","password","host","port","relative","path","directory","file","query","anchor"],q:{name:"queryKey",parser:/(?:^|&)([^&=]*)=?([^&]*)/g},parser:{strict:/^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/,loose:/^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/)?((?:(([^:@]*)(?::([^:@]*))?)?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/}};(function(){var a=this;var d;d=a.Raven={};var b=d;d.VERSION="0.4";var c=a.jQuery||a.Zepto||a.ender;d.loaded=false;d.options={secretKey:undefined,publicKey:undefined,servers:[],projectId:1,logger:"javascript",site:undefined,signatureUrl:undefined,fetchHeaders:false,testMode:false};d.funcNameRE=/function\s*([\w\-$]+)?\s*\(/i;d.config=function(e){if(typeof(e)==="string"){if(e.indexOf("http")===0){e=d.parseDSN(e)}else{throw"Base64 encoded config is no longer supported - use DSN"}}c.each(e,function(f,g){b.options[f]=g})};d.parseDSN=function(f){var h=parseUri(f);var g=h.path.lastIndexOf("/");var e;var i;if(g===-1){e=h.path.substr(1);i=""}else{i=h.path.substr(1,g);e=h.path.substr(g+1)}return{servers:[h.protocol+"://"+h.host+":"+h.port+"/"+i+"api/"+e+"/store/"],publicKey:h.user,secretKey:h.password,projectId:e}};d.getHeaders=function(){var e={};if(b.options.fetchHeaders){e=c.ajax({type:"HEAD",url:a.location,async:false}).getAllResponseHeaders()}e.Referer=document.referrer;e["User-Agent"]=navigator.userAgent;return e};d.parseHeaders=function(e){var f={};c.each(e.split("\n"),function(h,k){var g=k.slice(0,k.indexOf(":")),j=k.slice(k.indexOf(":")+2);f[g]=j});return f};d.getSignature=function(e,f,g){if(b.options.signatureUrl){c.post(b.options.signatureUrl,{message:e,timestamp:f},function(h){g(h.signature)})}else{g()}};d.getAuthHeader=function(e,f){var g="Sentry sentry_version=2.0, ";g+="sentry_timestamp="+f+", ";g+="sentry_client=raven-js/"+b.VERSION;if(b.options.publicKey){g+=", sentry_key="+b.options.publicKey}if(e){g+=", sentry_signature="+e}return g};d.captureException=function(i){var h,f,g;if(i.line){h=i.line}else{if(i.lineNumber){h=i.lineNumber}}if(i.sourceURL){g=i.sourceURL}else{if(i.fileName){g=i.fileName}}if(i.arguments&&i.stack){f=this.chromeTraceback(i)}else{if(i.stack){if(i.stack.indexOf("@")==-1){f=this.chromeTraceback(i)}else{f=this.firefoxTraceback(i)}}else{f=[{filename:g,lineno:h}];f=f.concat(this.otherTraceback(arguments.callee))}}b.process(i,g,h,f)};d.captureMessage=function(e){b.process(e)};d.trimString=function(e){return e.replace(/^\s+|\s+$/g,"")};d.chromeTraceback=function(k){var l,i,g,j,h=[],f=k.stack.split("\n");c.each(f.slice(1),function(m,e){l=d.trimString(e).slice(3);if(l=="unknown source"){return}else{l=l.split(" ")}if(l.length>2){i=l[0];g=l.slice(1).join(" ");j="(unknown)"}else{if(l.length==2){i=l[0];g=l[1]}else{i="(unknown)";g=l[0]}}if(g&&g!="(unknown source)"){if(g.slice(0,1)=="("){g=g.slice(1,-1).split(":")}else{g=g.split(":")}j=g.slice(-2)[0];g=g.slice(0,-2).join(":")}h.push({"function":i,filename:g,lineno:j})});return h};d.firefoxTraceback=function(l){var m,j,i,g,k,h=[],f=l.stack.split("\n");c.each(f,function(n,e){if(e){m=e.split("@");if(m[0]){j=m[0].split("(");if(j[1]!=")"){i=j[1].slice(0,-1).split(",")}else{i=undefined}if(j[0]){j=j[0]}else{j="(unknown)"}}else{j="(unknown)"}g=m[1].split(":");k=g.slice(-1)[0];g=g.slice(0,-1).join(":");h.push({"function":j,filename:g,lineno:k,vars:{"arguments":i}})}});return h};d.otherTraceback=function(j){var i,h,f="<anonymous>",g=[],e=9;while(j&&g.length<e){i=j.name||(this.funcNameRE.test(j.toString())?RegExp.$1||f:f);if(j.arguments){h=this.stringifyArguments(j.arguments)}else{h=undefined}g.push({filename:"(unknown source)",lineno:"(unknown)","function":i,post_context:j.toString().split("\n"),vars:{"arguments":h}});j=j.caller}return g};d.stringifyArguments=function(f){var i,e=this,h="<unknown>",g=[];c.each(f,function(k,j){if(j===undefined){g.push("undefined")}else{if(j===null){g.push("null")}else{if(j instanceof Array){g.push(e.stringifyArguments(j))}else{if(j.constructor){i=j.constructor.name||(e.funcNameRE.test(j.constructor.toString())?RegExp.$1||h:h);if(i=="String"){g.push('"'+j+'"')}else{if(i=="Number"||i=="Date"){g.push(j)}else{if(i=="Boolean"){g.push(j?"true":"false")}else{g.push(i)}}}}else{g.push(h)}}}}});return g};d.process=function(p,n,f,g,j){var l,o,h,i,k,e=a.location.origin+a.location.pathname,m=a.location.search.slice(1);if(typeof(p)==="object"){k=p.name;p=p.message}l=f?p+" at "+f:p;if(g){o={frames:g};n=n||g[0].filename}else{if(n){o={frames:[{filename:n,lineno:f}]}}}h={message:l,culprit:n,"sentry.interfaces.Stacktrace":o,"sentry.interfaces.Exception":{type:k,value:p},project:b.options.projectId,logger:b.options.logger,site:b.options.site};if(!b.options.testMode){h["sentry.interfaces.Http"]={url:e,querystring:m,headers:b.getHeaders()}}j=j||(new Date()).getTime();i=JSON.stringify(h);b.getSignature(i,j,function(q){var r=b.getAuthHeader(q,j);c.each(b.options.servers,function(s,t){c.ajax({type:"POST",url:t,data:i,headers:{"X-Sentry-Auth":r,Authentication:r}})})})}}).call(this);