From c2457e06d8394fc9bdbbd8f80e483bed9e42bb12 Mon Sep 17 00:00:00 2001 From: Peter 'Pita' Martischka Date: Wed, 17 Aug 2011 19:24:44 +0100 Subject: [PATCH] send client side javascript errors to the server --- node/server.js | 10 ++++++++++ static/js/pad_utils.js | 12 ++++++++++++ 2 files changed, 22 insertions(+) diff --git a/node/server.js b/node/server.js index 201e0659d..c90343593 100644 --- a/node/server.js +++ b/node/server.js @@ -312,6 +312,16 @@ async.waterfall([ }); }); + //The Etherpad client side sends information about client side javscript errors + app.post('/jserror', function(req, res) + { + new formidable.IncomingForm().parse(req, function(err, fields, files) + { + console.error("CLIENT SIDE JAVASCRIPT ERROR: " + fields.errorInfo); + res.end("OK"); + }); + }); + //serve index.html under / app.get('/', function(req, res) { diff --git a/static/js/pad_utils.js b/static/js/pad_utils.js index fc88553db..331590fed 100644 --- a/static/js/pad_utils.js +++ b/static/js/pad_utils.js @@ -461,3 +461,15 @@ var padutils = { }); } }; + +//send javascript errors to the server +window.onerror = function test (msg, url, linenumber) +{ + var errObj = {errorInfo: JSON.stringify({msg: msg, url: url, linenumber: linenumber, userAgent: navigator.userAgent})}; + var loc = document.location; + var url = loc.protocol + "//" + loc.hostname + ":" + loc.port + "/" + loc.pathname.substr(1, loc.pathname.indexOf("/p/")) + "jserror"; + + $.post(url, errObj); + + return false; +};