|
| 1 | +var Exceptional = { |
| 2 | + KEY : null, |
| 3 | + HOST : 'api.getexceptional.com', |
| 4 | + handle: function (msg,url,line) { |
| 5 | + if (Exceptional.KEY) { |
| 6 | + console.log(document) |
| 7 | + var request = document.createElement('iframe'); |
| 8 | + var protocol_version = 5; |
| 9 | + var backtrace_string = 'no backtrace'; |
| 10 | + request.style.width = '1px'; |
| 11 | + request.style.height = '1px'; |
| 12 | + request.style.display = 'none'; |
| 13 | + var url = 'http://' + Exceptional.HOST + '/api/errors/new?protocol_version=' + protocol_version + '&msg=' + escape(msg) + '&url=' + escape(url) + '&line=' + escape(line) + '&api_key=' + Exceptional.KEY + '&backtrace=' + backtrace_string; |
| 14 | + request.src = url; |
| 15 | + if (document.body) { |
| 16 | + document.body.appendChild(request); |
| 17 | + } else{ |
| 18 | + addLoadEvent(function() { |
| 19 | + document.body.appendChild(request); |
| 20 | + }); |
| 21 | + }; |
| 22 | + |
| 23 | + } else{ |
| 24 | + log('Exceptional.KEY is not set!') |
| 25 | + }; |
| 26 | + return true; |
| 27 | + }, |
| 28 | + setKey: function (key) { |
| 29 | + Exceptional.KEY = key; |
| 30 | + }, |
| 31 | + setHost: function (host) { |
| 32 | + Exceptional.HOST = host; |
| 33 | + } |
| 34 | +} |
| 35 | + |
| 36 | +window.onerror = function(msg, url, line) { |
| 37 | + Exceptional.handle(msg,url,line); |
| 38 | +}; |
| 39 | + |
| 40 | +// nice way to register the execution of some code when the page has finished loading - from http://simonwillison.net/2004/May/26/addLoadEvent/ |
| 41 | +function addLoadEvent(func) { |
| 42 | + var oldonload = window.onload; |
| 43 | + if (typeof window.onload != 'function') { |
| 44 | + window.onload = func; |
| 45 | + } else { |
| 46 | + window.onload = function() { |
| 47 | + if (oldonload) { |
| 48 | + oldonload(); |
| 49 | + } |
| 50 | + func(); |
| 51 | + } |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | +// from Paul Irish : http://paulirish.com/2009/log-a-lightweight-wrapper-for-consolelog/ |
| 56 | +window.log=function(){log.history=log.history||[];log.history.push(arguments);if(this.console){console.log(Array.prototype.slice.call(arguments))}}; |
0 commit comments