From 131a7c34a95019e8457c871821be678ac0247f7f Mon Sep 17 00:00:00 2001 From: Florent Bruneau Date: Sat, 7 Apr 2012 16:00:59 +0200 Subject: [PATCH] Log javascript errors. Signed-off-by: Florent Bruneau --- htdocs/javascript/core.js | 23 +++++++++++++++++++++++ modules/core.php | 9 +++++++++ 2 files changed, 32 insertions(+) diff --git a/htdocs/javascript/core.js b/htdocs/javascript/core.js index 6f57bb7..b4e950b 100644 --- a/htdocs/javascript/core.js +++ b/htdocs/javascript/core.js @@ -383,5 +383,28 @@ function previewWiki(idFrom, idTo, withTitle, idShow) } // }}} +// {{{ register error report + +$(function() { + $(window).error(function(error) { + if ($.xsrf_token) { + $.ajax({ + url: $.plURL('site_errors/register'), + type: 'POST', + data: { + url: "" + window.location, + token: $.xsrf_token, + error: JSON.stringify({ + message: error.originalEvent.message, + file: error.originalEvent.filename, + line: error.originalEvent.lineno + }) + } + }); + } + }); +}); + +// }}} // vim:set et sw=4 sts=4 sws=4 foldmethod=marker enc=utf-8: diff --git a/modules/core.php b/modules/core.php index 97eb6a6..d0168b2 100644 --- a/modules/core.php +++ b/modules/core.php @@ -35,6 +35,7 @@ class CoreModule extends PLModule 'assert_errors' => $this->make_hook('siteerror', AUTH_COOKIE, 'admin'), 'site_errors' => $this->make_hook('siteerror', AUTH_COOKIE, 'admin'), 'site_errors/rss' => $this->make_token_hook('siteerror_rss', AUTH_COOKIE, 'admin'), + 'site_errors/register' => $this->make_hook('register_error', AUTH_PUBLIC), 'embedded' => $this->make_hook('embedded', AUTH_PUBLIC), @@ -221,6 +222,14 @@ class CoreModule extends PLModule $page->assign('errors', PlErrorReport::iterate()); } + function handler_register_error($page) + { + if (S::has_xsrf_token() && Post::has('error') && Post::has('url')) { + PlErrorReport::report("Client error on " . Post::s('url') . ":\n\n" . Post::s('error')); + } + exit; + } + function handler_siteerror_rss(PlPage $page, PlUser $user) { return PlErrorReport::feed($page, $user); -- 2.1.4