{"action":"closed","issue":{"url":"https://api.github.com/repos/DarthFubuMVC/fubumvc/issues/932","labels_url":"https://api.github.com/repos/DarthFubuMVC/fubumvc/issues/932/labels{/name}","comments_url":"https://api.github.com/repos/DarthFubuMVC/fubumvc/issues/932/comments","events_url":"https://api.github.com/repos/DarthFubuMVC/fubumvc/issues/932/events","html_url":"https://github.com/DarthFubuMVC/fubumvc/issues/932","id":104721798,"number":932,"title":"Serenity should collect JS errors automatically","user":{"login":"jeremydmiller","id":179211,"avatar_url":"https://avatars.githubusercontent.com/u/179211?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremydmiller","html_url":"https://github.com/jeremydmiller","followers_url":"https://api.github.com/users/jeremydmiller/followers","following_url":"https://api.github.com/users/jeremydmiller/following{/other_user}","gists_url":"https://api.github.com/users/jeremydmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremydmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremydmiller/subscriptions","organizations_url":"https://api.github.com/users/jeremydmiller/orgs","repos_url":"https://api.github.com/users/jeremydmiller/repos","events_url":"https://api.github.com/users/jeremydmiller/events{/privacy}","received_events_url":"https://api.github.com/users/jeremydmiller/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/DarthFubuMVC/fubumvc/labels/Enhancement","name":"Enhancement","color":"02e10c"}],"state":"closed","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/DarthFubuMVC/fubumvc/milestones/7","html_url":"https://github.com/DarthFubuMVC/fubumvc/milestones/3.0","labels_url":"https://api.github.com/repos/DarthFubuMVC/fubumvc/milestones/7/labels","id":1206766,"number":7,"title":"3.0","description":"The big FubuMVC cleanup and consolidation effort before splitting off into \"Jasper\"","creator":{"login":"jeremydmiller","id":179211,"avatar_url":"https://avatars.githubusercontent.com/u/179211?v=3","gravatar_id":"","url":"https://api.github.com/users/jeremydmiller","html_url":"https://github.com/jeremydmiller","followers_url":"https://api.github.com/users/jeremydmiller/followers","following_url":"https://api.github.com/users/jeremydmiller/following{/other_user}","gists_url":"https://api.github.com/users/jeremydmiller/gists{/gist_id}","starred_url":"https://api.github.com/users/jeremydmiller/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jeremydmiller/subscriptions","organizations_url":"https://api.github.com/users/jeremydmiller/orgs","repos_url":"https://api.github.com/users/jeremydmiller/repos","events_url":"https://api.github.com/users/jeremydmiller/events{/privacy}","received_events_url":"https://api.github.com/users/jeremydmiller/received_events","type":"User","site_admin":false},"open_issues":30,"closed_issues":96,"state":"open","created_at":"2015-07-14T10:21:06Z","updated_at":"2015-09-03T22:01:06Z","due_on":"2015-07-31T05:00:00Z","closed_at":null},"comments":6,"created_at":"2015-09-03T15:26:29Z","updated_at":"2015-09-03T22:01:06Z","closed_at":"2015-09-03T22:01:06Z","body":"Adapt this from EH code:\r\n\r\n``` javascript\r\n\r\n'use strict';\r\n/*globals console:true, ErrorCollector:true*/\r\nif (typeof console === \"undefined\") {\r\n    console = {\r\n        log: function () { },\r\n        debug: function () { },\r\n        info: function () { },\r\n        warn: function () { },\r\n        error: function () { },\r\n        trace: function () { }\r\n    };\r\n}\r\n\r\nErrorCollector = (function (global, console) {\r\n    var self = {\r\n        errors: [],\r\n        registerError: function (msg) {\r\n            self.errors.push(msg);\r\n        }\r\n    };\r\n\r\n    var log = function (msg) {\r\n        self.registerError(msg);\r\n    };\r\n\r\n    function decorateWithLog(callback) {\r\n        return function(msg) {\r\n            log(msg);\r\n            if (callback) {\r\n              global.onerror = log; //callback(msg);\r\n            }\r\n        };\r\n    }\r\n\r\n    global.onerror = decorateWithLog(global.onerror);\r\n\r\n    console.error = decorateWithLog(console.error);\r\n    console.warn = decorateWithLog(console.warn);\r\n\r\n    return self;\r\n})(window, console);\r\n\r\n\r\n```\r\n\r\nHave this JS code injected by OWIN middleware in Serenity. And then do something like:\r\n\r\nDriver\r\n                               .InjectJavascript(\"return ErrorCollector.errors\")\r\n                               .As<IEnumerable<object>>()\r\n                               .Select(obj => new HtmlTag(\"pre\").Text(obj.ToString()));\r\n\r\n\r\nAdd this too:\r\n\r\n```\r\n    public class JavascriptErrorProvider : Report\r\n    {\r\n        private readonly FubuMvcSystem _system;\r\n\r\n        public JavascriptErrorProvider(FubuMvcSystem system)\r\n        {\r\n            _system = system;\r\n        }\r\n\r\n        public string ShortTitle\r\n        {\r\n            get { return \"Javascript\"; }\r\n        }\r\n\r\n        public int Count\r\n        {\r\n            get { return GenerateReports().Count(); }\r\n        }\r\n\r\n        public string ToHtml()\r\n        {\r\n            return GenerateReports().ToTagList().ToHtmlString();\r\n        }\r\n\r\n        public string Title\r\n        {\r\n            get { return \"Javascript Errors\"; }\r\n        }\r\n\r\n        public IEnumerable<HtmlTag> GenerateReports()\r\n        {\r\n            // todo handle any ErrorCollector is not defined errors properly\r\n            try\r\n            {\r\n                return _system.Application.Driver\r\n                               .InjectJavascript(\"return ErrorCollector.errors\")\r\n                               .As<IEnumerable<object>>()\r\n                               .Select(obj => new HtmlTag(\"pre\").Text(obj.ToString()));\r\n            }\r\n            catch (Exception)\r\n            {\r\n                return new List<HtmlTag>();\r\n            }\r\n        }\r\n    }\r\n```\r\n"}}