From d097ba7f08b035da50ddd634156b00b18c7d239f Mon Sep 17 00:00:00 2001 From: Erik Hesselink Date: Thu, 23 May 2013 12:17:27 +0000 Subject: [PATCH 1/5] Make sure fields are not too long. The Squash server does validation and crashes if the fields don't validate. This way we at least get some data in the system. --- .../javascripts/squash_javascript.min.js | 48 +++++++++---------- .../javascripts/squash_javascript.orig.js | 9 ++-- .../squash_javascript/client.coffee | 7 +-- 3 files changed, 34 insertions(+), 30 deletions(-) diff --git a/vendor/assets/javascripts/squash_javascript.min.js b/vendor/assets/javascripts/squash_javascript.min.js index 909c07c..95feba9 100644 --- a/vendor/assets/javascripts/squash_javascript.min.js +++ b/vendor/assets/javascripts/squash_javascript.min.js @@ -1,24 +1,24 @@ -(function(){var m,f={}.hasOwnProperty,h=[].slice,e="undefined"!==typeof exports&&null!==exports?exports:this,k=function(){},v;v=void 0;k.instance=function(){return null!=v?v:v=new m};e.SquashJavascript=k;var e=function(){TraceKit.report.subscribe(function(b,d){return SquashJavascript.instance().report(b,d)})},p,s,x,g;e.prototype.configure=function(b){var d,c,a;this.options||(this.options={disabled:!1,notifyPath:"/api/1.0/notify",transmitTimeout:15E3,ignoredExceptionClasses:[],ignoredExceptionMessages:{}}); -a=[];for(d in b)f.call(b,d)&&(c=b[d],a.push(this.options[d]=c));return a};e.prototype.notify=function(b,d){if(b instanceof Error)return b._squash_user_data=d,TraceKit.report(b);throw b;};e.prototype.report=function(b,d){var c,a,i,l,B,G,q,j,e,k,h,g;try{if(null!=(G=this.options)&&G.disabled)return!1;if(!(null!=(q=this.options)&&q.APIKey)||!(null!=(j=this.options)&&j.environment)||!(null!=(e=this.options)&&e.revision)||!(null!=(k=this.options)&&k.APIHost))return console.error("Missing required Squash configuration keys"), -!1;if(this.shouldIgnoreError(b)||!b.stack)return!1;a={};a.api_key=this.options.APIKey;a.environment=this.options.environment;a.client="javascript";a.revision=this.options.revision;a.class_name=null!=(h=b.type)?h:b.name;!b.name&&(l=b.message.match(/^(Uncaught )?(\w+): (.+)/))?(a.class_name=l[2],a.message=l[3]):a.message=b.message;null==a.class_name&&(a.class_name="Error");a.backtraces=x(b.stack);a.capture_method=b.mode;a.occurred_at=p(new Date);a.schema=window.location.protocol.replace(/:$/,"");a.host= -window.location.hostname;0b?"0"+b:b};return""+b.getUTCFullYear()+"-"+d(b.getUTCMonth()+ -1)+"-"+d(b.getUTCDate())+"T"+d(b.getUTCHours())+":"+d(b.getUTCMinutes())+":"+d(b.getUTCSeconds())+"Z"};s=function(b,d){var c,a,i;if(b instanceof Array){a=0;for(i=b.length;af;++f)if(c=e[i-f]+c,void 0!==c&&((j=d.exec(c))||(j=b.exec(c))))return j[1];return"?"}function h(a,b){var l=m(a),c=[],d=!1;if(!l.length)return null;for(var b=b-1,e=b-2,f=b+2;e","(?:>|>)").replace("&","(?:&|&)").replace('"','(?:"|")').replace(/\s+/g,"\\s+")}function v(a,b){for(var l,c,d=0,e=b.length;dl&&(c=a.exec(b[l]))?c.index:null} -function s(a){var b=[window.location.href],c=document.getElementsByTagName("script"),a=""+a,d;for(d=0;d]+)>|([^\)]+))\((.*)\) in (.*):\s*$/i,s=a.stacktrace.split("\n"),q=[],j,x=0,L=s.length;xz.length)c=null;else{D=/^\s*Line (\d+) of linked script ((?:file|http)\S+)(?:: in function (\S+))?\s*$/i;r=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|http)\S+)(?:: in function (\S+))?\s*$/i;t=/^\s*Line (\d+) of function script\s*$/i;var C=[],n=document.getElementsByTagName("script"),F=[],y,u,H,A;for(u in n)n.hasOwnProperty(u)&&!n[u].src&&F.push(n[u]);u=2;for(H=z.length;ub?"0"+b:b}; +return""+b.getUTCFullYear()+"-"+c(b.getUTCMonth()+1)+"-"+c(b.getUTCDate())+"T"+c(b.getUTCHours())+":"+c(b.getUTCMinutes())+":"+c(b.getUTCSeconds())+"Z"};s=function(b,c){var e,a,d;if(b instanceof Array){a=0;for(d=b.length;ag;++g)if(e=f[a-g]+e,void 0!==e&&((h=d.exec(e))||(h=c.exec(e))))return h[1];return"?"}function d(b,a){var c=q(b),d=[],e=!1;if(!c.length)return null;a-=1;for(var f=a-2,h=a+2;f","(?:>|>)").replace("&","(?:&|&)").replace('"','(?:"|")').replace(/\s+/g,"\\s+")}function l(b,a){for(var c,d,e=0,f=a.length;ec&&(d=b.exec(a[c]))?d.index:null}function b(b){var a=[window.location.href],c=document.getElementsByTagName("script");b=""+b;var d;for(d=0;d]+)>|([^\)]+))\((.*)\) in (.*):\s*$/i,m=a.stacktrace.split("\n"), +k=[],h,n=0,C=m.length;ny.length)c=null;else{D=/^\s*Line (\d+) of linked script ((?:file|http)\S+)(?:: in function (\S+))?\s*$/i;r=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|http)\S+)(?:: in function (\S+))?\s*$/i;t=/^\s*Line (\d+) of function script\s*$/i;var B=[],p=document.getElementsByTagName("script"),F=[],w,u,L,z;for(u in p)p.hasOwnProperty(u)&&!p[u].src&&F.push(p[u]);u=2;for(L=y.length;u 0) { fields.port = window.location.port; } - fields.path = window.location.pathname; - fields.query = window.location.search; + fields.path = window.location.pathname.substring(0, 500); + fields.query = window.location.search.substring(0, 255); if (window.location.hash !== '') { - fields.fragment = window.location.hash; + fields.fragment = window.location.hash.substring(0, 255); } fields.user_agent = navigator.userAgent; fields.screen_width = screen.width; diff --git a/vendor/assets/javascripts/squash_javascript/client.coffee b/vendor/assets/javascripts/squash_javascript/client.coffee index da6a5f5..3a34c8b 100644 --- a/vendor/assets/javascripts/squash_javascript/client.coffee +++ b/vendor/assets/javascripts/squash_javascript/client.coffee @@ -91,6 +91,7 @@ class _SquashJavascript fields.message = matches[3] else fields.message = info.message + fields.message = fields.message.substring(0,1000) if fields.message fields.class_name ?= 'Error' # when all else fails fields.backtraces = buildBacktrace(info.stack) @@ -100,9 +101,9 @@ class _SquashJavascript fields.schema = window.location.protocol.replace(/:$/, '') fields.host = window.location.hostname fields.port = window.location.port if window.location.port.length > 0 - fields.path = window.location.pathname - fields.query = window.location.search - fields.fragment = window.location.hash if window.location.hash != '' + fields.path = window.location.pathname.substring(0,500) + fields.query = window.location.search.substring(0,255) + fields.fragment = window.location.hash.substring(0,255) if window.location.hash != '' fields.user_agent = navigator.userAgent From 9f752cb2b74d36eb1f9b426c4bad80ba158ab220 Mon Sep 17 00:00:00 2001 From: Erik Hesselink Date: Thu, 23 May 2013 12:22:07 +0000 Subject: [PATCH 2/5] Don't send empty url or 0 as line number. The Squash server doesn't allow this; this way, we get some data in the system. --- vendor/assets/javascripts/squash_javascript.min.js | 4 ++-- vendor/assets/javascripts/squash_javascript.orig.js | 4 ++-- vendor/assets/javascripts/squash_javascript/client.coffee | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/vendor/assets/javascripts/squash_javascript.min.js b/vendor/assets/javascripts/squash_javascript.min.js index 95feba9..c397c7c 100644 --- a/vendor/assets/javascripts/squash_javascript.min.js +++ b/vendor/assets/javascripts/squash_javascript.min.js @@ -5,8 +5,8 @@ window.location.protocol.replace(/:$/,"");a.host=window.location.hostname;0b?"0"+b:b}; -return""+b.getUTCFullYear()+"-"+c(b.getUTCMonth()+1)+"-"+c(b.getUTCDate())+"T"+c(b.getUTCHours())+":"+c(b.getUTCMinutes())+":"+c(b.getUTCSeconds())+"Z"};s=function(b,c){var e,a,d;if(b instanceof Array){a=0;for(d=b.length;a +b?"0"+b:b};return""+b.getUTCFullYear()+"-"+c(b.getUTCMonth()+1)+"-"+c(b.getUTCDate())+"T"+c(b.getUTCHours())+":"+c(b.getUTCMinutes())+":"+c(b.getUTCSeconds())+"Z"};s=function(b,c){var e,a,d;if(b instanceof Array){a=0;for(d=b.length;a cline && cline.length > 200) - backtraces.push {url: line.url, line: line.line, column: line.column, symbol: line.func, context: context, type: 'minified'} + backtraces.push {url: line.url || "unknown", line: line.line || 1, column: line.column, symbol: line.func, context: context, type: 'minified'} return [ {name: "Active Thread", faulted: true, backtrace: backtraces} ] ISODateString = (d) -> From d15fe3f66e01dadd80057799d10c7a66ccdebb15 Mon Sep 17 00:00:00 2001 From: Erik Hesselink Date: Thu, 23 May 2013 12:23:57 +0000 Subject: [PATCH 3/5] Make sure there is always one backtrace line. The Squash server doesn't allow occurrences without any backtrace lines. This way we get at least some data. --- vendor/assets/javascripts/squash_javascript.min.js | 6 +++--- vendor/assets/javascripts/squash_javascript.orig.js | 8 ++++++++ vendor/assets/javascripts/squash_javascript/client.coffee | 5 +++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/vendor/assets/javascripts/squash_javascript.min.js b/vendor/assets/javascripts/squash_javascript.min.js index c397c7c..6db0033 100644 --- a/vendor/assets/javascripts/squash_javascript.min.js +++ b/vendor/assets/javascripts/squash_javascript.min.js @@ -5,11 +5,11 @@ window.location.protocol.replace(/:$/,"");a.host=window.location.hostname;0 -b?"0"+b:b};return""+b.getUTCFullYear()+"-"+c(b.getUTCMonth()+1)+"-"+c(b.getUTCDate())+"T"+c(b.getUTCHours())+":"+c(b.getUTCMinutes())+":"+c(b.getUTCSeconds())+"Z"};s=function(b,c){var e,a,d;if(b instanceof Array){a=0;for(d=b.length;ab?"0"+b:b};return""+b.getUTCFullYear()+"-"+c(b.getUTCMonth()+1)+"-"+c(b.getUTCDate())+"T"+c(b.getUTCHours())+":"+c(b.getUTCMinutes())+":"+c(b.getUTCSeconds())+"Z"};s=function(b,c){var e,a,d;if(b instanceof Array){a=0;for(d=b.length;ag;++g)if(e=f[a-g]+e,void 0!==e&&((h=d.exec(e))||(h=c.exec(e))))return h[1];return"?"}function d(b,a){var c=q(b),d=[],e=!1;if(!c.length)return null;a-=1;for(var f=a-2,h=a+2;f","(?:>|>)").replace("&","(?:&|&)").replace('"','(?:"|")').replace(/\s+/g,"\\s+")}function l(b,a){for(var c,d,e=0,f=a.length;ec&&(d=b.exec(a[c]))?d.index:null}function b(b){var a=[window.location.href],c=document.getElementsByTagName("script");b=""+b;var d;for(d=0;d cline && cline.length > 200) backtraces.push {url: line.url || "unknown", line: line.line || 1, column: line.column, symbol: line.func, context: context, type: 'minified'} + # The server doesn't allow empty backtraces. We fake one to + # make sure the error arrives anyway. + if backtraces.length == 0 + backtraces.push {url: "fake", line: 1, symbol: "", type: 'minified'} + return [ {name: "Active Thread", faulted: true, backtrace: backtraces} ] ISODateString = (d) -> From 693561a95e3173d1a742beb2f076545e33794ea6 Mon Sep 17 00:00:00 2001 From: Erik Hesselink Date: Mon, 15 Jul 2013 09:51:06 +0000 Subject: [PATCH 4/5] Tracekit: also parse stack lines from https urls. --- vendor/assets/javascripts/squash_javascript/tracekit.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/vendor/assets/javascripts/squash_javascript/tracekit.js b/vendor/assets/javascripts/squash_javascript/tracekit.js index 7206bd6..941b57c 100644 --- a/vendor/assets/javascripts/squash_javascript/tracekit.js +++ b/vendor/assets/javascripts/squash_javascript/tracekit.js @@ -548,8 +548,8 @@ TraceKit.computeStackTrace = (function () { return null; } - var chrome = /^\s*at (?:new )?(.+) (?:\[as \S+\] )?\(((?:file|http):.*?):(\d+)(?::(\d+))?\)\s*$/i, - gecko = /^\s*(\S*)(?:\((.*?)\))?@((?:file|http).*?):(\d+)(?::(\d+))?\s*$/i, + var chrome = /^\s*at (?:new )?(.+) (?:\[as \S+\] )?\(((?:file|https?):.*?):(\d+)(?::(\d+))?\)\s*$/i, + gecko = /^\s*(\S*)(?:\((.*?)\))?@((?:file|https?).*?):(\d+)(?::(\d+))?\s*$/i, lines = ex.stack.split("\n"), stack = [], parts, @@ -674,8 +674,8 @@ TraceKit.computeStackTrace = (function () { return null; } - var lineRE1 = /^\s*Line (\d+) of linked script ((?:file|http)\S+)(?:: in function (\S+))?\s*$/i, - lineRE2 = /^\s*Line (\d+) of inline#(\d+) script in ((?:file|http)\S+)(?:: in function (\S+))?\s*$/i, + var lineRE1 = /^\s*Line (\d+) of linked script ((?:file|https?)\S+)(?:: in function (\S+))?\s*$/i, + lineRE2 = /^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?)\S+)(?:: in function (\S+))?\s*$/i, lineRE3 = /^\s*Line (\d+) of function script\s*$/i, stack = [], scripts = document.getElementsByTagName('script'), From 1934eb25bcb0dac057546c7821511aa354ebeb0a Mon Sep 17 00:00:00 2001 From: Erik Hesselink Date: Mon, 15 Jul 2013 09:51:55 +0000 Subject: [PATCH 5/5] Regenerate minified sources. --- vendor/assets/javascripts/squash_javascript.min.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/assets/javascripts/squash_javascript.min.js b/vendor/assets/javascripts/squash_javascript.min.js index 6db0033..43a34bd 100644 --- a/vendor/assets/javascripts/squash_javascript.min.js +++ b/vendor/assets/javascripts/squash_javascript.min.js @@ -16,9 +16,9 @@ var d;c-=1;return a&&a.length>c&&(d=b.exec(a[c]))?d.index:null}function b(b){var "\\s+"));if(d=l(d,a))return d;if(c=/^function on([\w$]+)\s*\(event\)\s*\{\s*(\S[\s\S]*\S)\s*\}\s*$/.exec(b)){b=c[1];c=s(c[2]);d=RegExp("on"+b+"=[\\'\"]\\s*"+c+"\\s*[\\'\"]","i");if(d=l(d,a[0]))return d;d=RegExp(c);if(d=l(d,a))return d}return null}function c(b,a,c,e){a={url:a,line:c};if(a.url&&a.line){b.incomplete=!1;a.func||(a.func=g(a.url,a.line));a.context||(a.context=d(a.url,a.line));if(e=/ '([^']+)' /.exec(e))a.column=A(e[1],a.url,a.line);if(0]+)>|([^\)]+))\((.*)\) in (.*):\s*$/i,m=a.stacktrace.split("\n"), -k=[],h,n=0,C=m.length;ny.length)c=null;else{D=/^\s*Line (\d+) of linked script ((?:file|http)\S+)(?:: in function (\S+))?\s*$/i;r=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|http)\S+)(?:: in function (\S+))?\s*$/i;t=/^\s*Line (\d+) of function script\s*$/i;var B=[],p=document.getElementsByTagName("script"),F=[],w,u,L,z;for(u in p)p.hasOwnProperty(u)&&!p[u].src&&F.push(p[u]);u=2;for(L=y.length;uy.length)c=null;else{D=/^\s*Line (\d+) of linked script ((?:file|https?)\S+)(?:: in function (\S+))?\s*$/i;r=/^\s*Line (\d+) of inline#(\d+) script in ((?:file|https?)\S+)(?:: in function (\S+))?\s*$/i;t=/^\s*Line (\d+) of function script\s*$/i;var B=[],p=document.getElementsByTagName("script"),F=[],w,u,L,z;for(u in p)p.hasOwnProperty(u)&&!p[u].src&&F.push(p[u]);u=2;for(L=y.length;u< +L;u+=2){p=null;if(w=D.exec(y[u]))p={url:w[2],func:w[3],line:+w[1]};else if(w=r.exec(y[u])){var p={url:w[3],func:w[4]},R=+w[1],M=F[w[2]-1];if(M&&(z=q(p.url))){z=z.join("\n");var N=z.indexOf(M.innerText);0<=N&&(p.line=R+z.substring(0,N).split("\n").length)}}else if(w=t.exec(y[u])){var O=window.location.href.replace(/#.*$/,""),S=w[1],T=RegExp(s(y[u+1]));z=l(T,[O]);p={url:O,line:z?z.line:S,func:""}}if(p){p.func||(p.func=g(p.url,p.line));var E=d(p.url,p.line),U=E?E[Math.floor(E.length/2)]:null;E&&U.replace(/^\s*/, "")===y[u+1].replace(/^\s*/,"")?p.context=E:p.context=[y[u+1]];B.push(p)}}c=B.length?{mode:"multiline",name:a.name,message:y[0],stack:B}:null}if(c)return c}catch(V){if(x)throw V;}try{if(c=e(a,b+1))return c}catch(W){if(x)throw W;}return{mode:"failed"}}var x=!1,C={};a.augmentStackTraceWithInitialElement=c;a.guessFunctionName=g;a.gatherContext=d;a.ofCaller=function(b){b=(void 0===b?0:+b)+1;try{0()}catch(c){return a(c,b+1)}return null};return a}(); (function(m){var q=Array.prototype.slice,g=m.setTimeout;m.setTimeout=function(){var d=q.call(arguments,0),m=d[0];d[0]=function(){try{m.apply(this,arguments)}catch(d){throw TraceKit.report(d),d;}};return g.apply(this,d)};var d=m.setInterval;m.setInterval=function(){var f=q.call(arguments,0),g=f[0];f[0]=function(){try{g.apply(this,arguments)}catch(d){throw TraceKit.report(d),d;}};return d.apply(this,f)}})(window);