异常中心如何工作?

时间:2010-04-20 14:49:15

标签: javascript exceptionhub

只是想知道ExceptionHub http://www.exceptionhub.com/如何跟踪用户浏览器中的javascript错误?

3 个答案:

答案 0 :(得分:1)

我以前没有使用过这个产品,但是通过查看它们提供的产品,我猜测它是如何工作的:跟踪脚本可能会扫描安装它的页面并包装所有JavaScript代码可以在<script>块中找到(例如,在onclick标签内或在try-catch}中的处理程序中,并且当发生异常时,它获得控制并执行它应该做的任何事情,例如。报告例外。

答案 1 :(得分:0)

您可以通过阅读代码来学习:http://js.exceptionhub.com/javascripts/eh.js

答案 2 :(得分:0)

查看脚本后。似乎@casblanca是正确的。似乎有一个try catch包装所有事件,包括setTimeout和setInterval。

initialFunctionWrap: function () {
    if (this.initial_wrap_ran === false) {
        this.initial_wrap_ran = true;
        var b = [];
        if (this.firefox) {
            b = ["Console", "JSpec", "printStackTrace", "ExceptionHub", "EHConsole", "getInterface", "_FirebugCommandLine", "_firebug", "_getFirebugConsoleElement", "loadFirebugConsole", "console", "window", "_FirebugConsole", "document", "navigator", "netscape", "XPCSafeJSObjectWrapper", "XPCNativeWrapper", "Components", "sessionStorage", "globalStorage", "getComputedStyle", "dispatchEvent", "removeEventListener", "name", "parent", "top", "dump", "getSelection", "scrollByLines", "scrollbars", "scrollX", "scrollY", "scrollTo", "scrollBy", "scrollByPages", "sizeToContent", "setTimeout", "setInterval", "clearTimeout", "clearInterval", "setResizable", "captureEvents", "releaseEvents", "routeEvent", "enableExternalCapture", "disableExternalCapture", "open", "openDialog", "frames", "applicationCache", "self", "screen", "history", "content", "menubar", "toolbar", "locationbar", "personalbar", "statusbar", "directories", "closed", "crypto", "pkcs11", "controllers", "opener", "status", "defaultStatus", "location", "innerWidth", "innerHeight", "outerWidth", "outerHeight", "screenX", "screenY", "mozInnerScreenX", "mozInnerScreenY", "pageXOffset", "pageYOffset", "scrollMaxX", "scrollMaxY", "length", "fullScreen", "alert", "confirm", "prompt", "focus", "blur", "back", "forward", "home", "stop", "print", "moveTo", "moveBy", "resizeTo", "resizeBy", "scroll", "close", "updateCommands", "find", "atob", "btoa", "frameElement", "showModalDialog", "postMessage", "addEventListener", "localStorage", "nsXPCComponents", "Cufon"]
        } else {
            if (window.opera) {
                b = ["open", "print", "stop", "getComputedStyle", "getSelection", "releaseEvents", "captureEvents", "dispatchEvent", "alert", "confirm", "prompt", "setTimeout", "setInterval", "addEventStream", "removeEventStream", "clearInterval", "clearTimeout", "back", "forward", "attachEvent", "detachEvent", "addEventListener", "removeEventListener", "navigate", "DOMParser", "XMLHttpRequest", "XMLSerializer", "XPathEvaluator", "XSLTProcessor", "opera", "Image", "Option", "frames", "Audio", "SVGUnitTypes", "SVGZoomAndPan", "java", "netscape", "sun", "Packages", "ImageData", "ByteArray", "printStackTrace", "ExceptionHub", "EHConsole", "props", "prop", "console", "closed", "defaultStatus", "document", "event", "frameElement", "history", "innerHeight", "innerWidth", "location", "name", "navigator", "opener", "outerHeight", "outerWidth", "pageXOffset", "pageYOffset", "parent", "screen", "screenLeft", "screenTop", "screenX", "screenY", "self", "status", "top", "window", "length", "Cufon"]
            } else {
                if (window.chrome) {
                    b = ["JSpec", "captures", "top", "window", "location", "chromium", "chrome", "external", "document", "ExceptionHub", "EHConsole", "SVGPathSegLinetoVerticalRel", "SVGFESpotLightElement", "SVGAnimatedNumber", "SVGPoint", "SVGScriptElement", "SVGFEPointLightElement", "SVGPathSegList", "SVGImageElement", "SharedWorker", "SVGAElement", "SVGAnimatedRect", "SVGGElement", "SVGLinearGradientElement", "SVGForeignObjectElement", "SVGAnimateElement", "SVGFontElement", "SVGFontFaceElement", "SVGPathSegCurvetoQuadraticSmoothRel", "SVGStopElement", "SVGViewElement", "SVGPathSegMovetoRel", "SVGFEImageElement", "SVGPathSegMovetoAbs", "SVGAnimatedTransformList", "SVGPathSegCurvetoQuadraticAbs", "SVGFilterElement", "SVGFETileElement", "SVGFEComponentTransferElement", "SVGAnimatedPreserveAspectRatio", "SVGRectElement", "SVGLineElement", "SVGDocument", "MessagePort", "SVGDescElement", "SVGPathSegLinetoRel", "SVGEllipseElement", "SVGFEFuncRElement", "HTMLAllCollection", "SVGAnimatedNumberList", "SVGElementInstance", "SVGPathSegLinetoHorizontalRel", "SVGPathSegLinetoHorizontalAbs", "SVGComponentTransferFunctionElement", "SVGStyleElement", "SVGNumberList", "Blob", "SVGFEFloodElement", "SVGFEBlendElement", "SVGFEGaussianBlurElement", "SVGTextElement", "SVGFEOffsetElement", "RGBColor", "SVGGlyphElement", "SVGZoomEvent", "SVGElementInstanceList", "SVGFEDisplacementMapElement", "SVGPathSegCurvetoCubicSmoothRel", "SVGFEDistantLightElement", "ImageData", "SVGFEFuncBElement", "SVGCircleElement", "SVGSetElement", "SVGFEMergeElement", "SVGFESpecularLightingElement", "SVGNumber", "SVGFontFaceSrcElement", "SVGElement", "SVGMissingGlyphElement", "SVGPathSegLinetoVerticalAbs", "SVGTextPositioningElement", "SVGFEFuncGElement", "SVGPathSegCurvetoQuadraticRel", "SVGPathSegCurvetoQuadraticSmoothAbs", "SVGRect", "SVGFontFaceFormatElement", "SVGAnimateTransformElement", "SVGPathSegCurvetoCubicSmoothAbs", "SVGPathSegClosePath", "SVGPathSegArcRel", "SVGAnimatedString", "SVGTransformList", "SVGFEMorphologyElement", "SVGAnimatedLength", "SVGPolygonElement", "SVGPathSegLinetoAbs", "SVGMaskElement", "SVGPathElement", "SVGStringList", "MessageChannel", "BeforeLoadEvent", "PageTransitionEvent", "SVGAnimatedLengthList", "SVGRadialGradientElement", "SVGCursorElement", "SVGPathSegCurvetoCubicAbs", "SVGUseElement", "SVGSwitchElement", "SVGLengthList", "SVGPathSegArcAbs", "SVGAnimatedBoolean", "SVGFontFaceUriElement", "SVGPointList", "SVGPathSegCurvetoCubicRel", "SVGMetadataElement", "SVGTitleElement", "SVGAnimatedAngle", "SVGAnimateColorElement", "SVGMatrix", "SVGSymbolElement", "SVGFEDiffuseLightingElement", "SVGFETurbulenceElement", "SVGAnimatedEnumeration", "SVGFEMergeNodeElement", "SVGAnimatedInteger", "SVGDefsElement", "SVGSVGElement", "SVGAltGlyphElement", "SVGClipPathElement", "SVGPolylineElement", "SVGPatternElement", "SVGFECompositeElement", "SVGFEColorMatrixElement", "SVGTRefElement", "SVGFEFuncAElement", "WebSocket", "SVGTSpanElement", "SVGFontFaceNameElement", "HTMLButtonElement", "webkitNotifications", "pageYOffset", "EntityReference", "NodeList", "screenY", "navigator", "MimeTypeArray", "offscreenBuffering", "sessionStorage", "OverflowEvent", "HTMLTableColElement", "HTMLOptionElement", "HTMLInputElement", "defaultStatus", "SVGMarkerElement", "HTMLLinkElement", "WebKitCSSTransformValue", "MutationEvent", "Clipboard", "HTMLTableElement", "toolbar", "innerHeight", "applicationCache", "pageXOffset", "Element", "opener", "CSSStyleSheet", "StyleSheetList", "HTMLHRElement", "WebKitPoint", "media", "screenLeft", "SVGGradientElement", "HTMLDivElement", "HTMLQuoteElement", "KeyboardEvent", "screenX", "RangeException", "SVGTextPathElement", "HTMLLegendElement", "MouseEvent", "MediaError", "HTMLObjectElement", "HTMLFontElement", "WebKitTransitionEvent", "MediaList", "SVGPaint", "Document", "XPathException", "innerWidth", "TextMetrics", "personalbar", "HTMLHeadElement", "ProgressEvent", "Node", "CSSPageRule", "CharacterData", "length", "ClientRect", "Option", "Notation", "StorageEvent", "HTMLFieldSetElement", "HTMLVideoElement", "locationbar", "SVGRenderingIntent", "UIEvent", "HTMLTableRowElement", "HTMLDListElement", "File", "CSSValue", "HTMLParamElement", "HTMLModElement", "scrollY", "outerHeight", "CSSFontFaceRule", "SVGPathSeg", "Rect", "CSSStyleDeclaration", "StyleSheet", "SVGColor", "clientInformation", "HTMLStyleElement", "HTMLBaseElement", "HTMLBRElement", "HTMLHtmlElement", "HTMLTextAreaElement", "HTMLBaseFontElement", "scrollbars", "screen", "localStorage", "defaultstatus", "HTMLCanvasElement", "ProcessingInstruction", "HTMLFrameElement", "frames", "HTMLElement", "HTMLSelectElement", "HTMLIsIndexElement", "HTMLDocument", "HTMLCollection", "HTMLDirectoryElement", "CSSMediaRule", "MessageEvent", "DOMException", "CSSRule", "WebKitCSSMatrix", "status", "HTMLScriptElement", "DOMImplementation", "SVGLength", "HTMLOptGroupElement", "HTMLAreaElement", "HTMLFrameSetElement", "name", "self", "HTMLIFrameElement", "Comment", "Event", "Storage", "XMLSerializer", "statusbar", "Range", "HTMLPreElement", "Image", "parent", "closed", "crypto", "CSSVariablesDeclaration", "HTMLOListElement", "HTMLFormElement", "DOMParser", "console", "EventException", "scrollX", "HTMLMediaElement", "XMLDocument", "HTMLHeadingElement", "XMLHttpRequest", "TextEvent", "event", "CSSVariablesRule", "HTMLAppletElement", "devicePixelRatio", "FileList", "CanvasRenderingContext2D", "HTMLMarqueeElement", "WebKitCSSKeyframesRule", "XSLTProcessor", "CSSImportRule", "CSSRuleList", "SVGTransform", "SVGTextContentElement", "HTMLTableCellElement", "DocumentFragment", "SVGPreserveAspectRatio", "HTMLMapElement", "XPathResult", "HTMLLIElement", "Plugin", "HTMLParagraphElement", "HTMLBlockquoteElement", "outerWidth", "CSSStyleRule", "Text", "HTMLUListElement", "CSSPrimitiveValue", "HTMLEmbedElement", "PluginArray", "ClientRectList", "CSSCharsetRule", "menubar", "HTMLBodyElement", "HTMLAudioElement", "CDATASection", "WebKitCSSKeyframeRule", "Audio", "history", "Entity", "HTMLTableCaptionElement", "MimeType", "SVGException", "NamedNodeMap", "XMLHttpRequestUpload", "WebKitAnimationEvent", "HTMLMenuElement", "SVGAngle", "XPathEvaluator", "HTMLImageElement", "NodeFilter", "Attr", "Counter", "CSSValueList", "XMLHttpRequestException", "WheelEvent", "SVGUnitTypes", "HTMLLabelElement", "HTMLAnchorElement", "frameElement", "DocumentType", "HTMLTableSectionElement", "HTMLTitleElement", "HTMLMetaElement", "Worker", "screenTop", "onwebkittransitionend", "onmouseover", "onmouseup", "ondragend", "onerror", "onsearch", "close", "onkeydown", "ondragstart", "onseeking", "postMessage", "onfocus", "ondurationchange", "onreset", "onkeyup", "onpause", "onended", "ondragenter", "onpagehide", "ondblclick", "onloadeddata", "ondragleave", "onvolumechange", "onbeforeunload", "onresize", "blur", "onloadstart", "onmousedown", "onloadedmetadata", "onabort", "onstalled", "onpageshow", "ononline", "onkeypress", "onclick", "oninvalid", "onsubmit", "onseeked", "onoffline", "onemptied", "onwebkitanimationiteration", "onsuspend", "onstorage", "onload", "onwaiting", "oncanplay", "onratechange", "ondragover", "onunload", "onpopstate", "onplay", "onwebkitanimationstart", "onplaying", "oncanplaythrough", "onselect", "focus", "onmousemove", "ondrag", "onmessage", "onscroll", "ontimeupdate", "onchange", "oncontextmenu", "onmousewheel", "onblur", "onmouseout", "oninput", "ondrop", "onwebkitanimationend", "onprogress", "onhashchange", "getSelection", "print", "stop", "open", "showModalDialog", "alert", "confirm", "prompt", "find", "scrollBy", "scrollTo", "scroll", "moveBy", "moveTo", "resizeBy", "resizeTo", "setTimeout", "clearTimeout", "setInterval", "clearInterval", "atob", "btoa", "addEventListener", "removeEventListener", "captureEvents", "releaseEvents", "getComputedStyle", "getMatchedCSSRules", "webkitConvertPointFromPageToNode", "webkitConvertPointFromNodeToPage", "openDatabase", "dispatchEvent", "Cufon", "FormData"]
                } else {
                    b = ["JSpec", "printStackTrace", "ExceptionHub", "EHConsole", "document", "window", "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError", "getComputedStyle", "getMatchedCSSRules", "moveBy", "find", "resizeTo", "clearTimeout", "btoa", "setTimeout", "scrollBy", "print", "resizeBy", "atob", "openDatabase", "moveTo", "scroll", "confirm", "showModalDialog", "close", "clearInterval", "webkitConvertPointFromNodeToPage", "open", "prompt", "focus", "blur", "scrollTo", "removeEventListener", "postMessage", "setInterval", "getSelection", "alert", "stop", "webkitConvertPointFromPageToNode", "addEventListener", "dispatchEvent", "captureEvents", "releaseEvents", "_inspectorCommandLineAPI", "frames", "HTMLBodyElement", "onseeking", "menubar", "onended", "onsuspend", "pageXOffset", "length", "CSSPrimitiveValue", "frameElement", "HTMLMenuElement", "NodeFilter", "MouseEvent", "TextEvent", "onreset", "HTMLQuoteElement", "onwebkitanimationiteration", "WebKitPoint", "HTMLIsIndexElement", "XMLHttpRequestUpload", "CSSCharsetRule", "HTMLAppletElement", "HTMLCollection", "statusbar", "XMLHttpRequestException", "HTMLStyleElement", "ondragleave", "DOMException", "HTMLFrameSetElement", "clientInformation", "localStorage", "onloadedmetadata", "HTMLUListElement", "CharacterData", "name", "ondragstart", "HTMLLegendElement", "XPathResult", "HTMLPreElement", "onkeydown", "onwebkitanimationstart", "ondblclick", "XSLTProcessor", "CSSRuleList", "onmousemove", "WebKitTransitionEvent", "outerHeight", "CSSVariablesDeclaration", "ondragend", "history", "SVGUnitTypes", "top", "parent", "CanvasRenderingContext2D", "TextMetrics", "ClientRectList", "HTMLButtonElement", "onunload", "HTMLMapElement", "scrollY", "Plugin", "CSSStyleSheet", "ondrag", "Attr", "EntityReference", "HTMLTableCaptionElement", "HTMLObjectElement", "self", "MutationEvent", "pageYOffset", "HTMLInputElement", "screenLeft", "onkeyup", "HTMLScriptElement", "onmousewheel", "onstorage", "HTMLOListElement", "HTMLCanvasElement", "CSSFontFaceRule", "XMLDocument", "HTMLBRElement", "CSSStyleRule", "HTMLFontElement", "HTMLTitleElement", "Node", "HTMLTableSectionElement", "Text", "onclick", "HTMLOptionElement", "File", "onvolumechange", "StyleSheetList", "Range", "onmouseover", "HTMLAnchorElement", "innerHeight", "onplaying", "CSSMediaRule", "HTMLEmbedElement", "NodeList", "SVGMarkerElement", "onmouseup", "WebKitAnimationEvent", "SVGColor", "HTMLParamElement", "offscreenBuffering", "HTMLTextAreaElement", "onratechange", "locationbar", "SVGLength", "KeyboardEvent", "MimeTypeArray", "ondragover", "HTMLDivElement", "HTMLBaseElement", "HTMLBaseFontElement", "onsubmit", "HTMLIFrameElement", "HTMLBlockquoteElement", "HTMLAudioElement", "SVGPreserveAspectRatio", "HTMLLIElement", "SVGAngle", "location", "onstalled", "scrollbars", "HTMLMarqueeElement", "SVGPaint", "Entity", "onprogress", "onwaiting", "HTMLModElement", "HTMLFormElement", "opener", "ontimeupdate", "onfocus", "outerWidth", "onplay", "HTMLHeadElement", "ondurationchange", "oncanplay", "onemptied", "MimeType", "HTMLImageElement", "CDATASection", "closed", "event", "DOMParser", "CSSValueList", "navigator", "screen", "FileList", "sessionStorage", "ProcessingInstruction", "ononline", "oncontextmenu", "RangeException", "onoffline", "WheelEvent", "onresize", "Storage", "innerWidth", "Rect", "MessageEvent", "StorageEvent", "HTMLElement", "onsearch", "onseeked", "Counter", "NamedNodeMap", "HTMLOptGroupElement", "HTMLHeadingElement", "Worker", "ondragenter", "onmessage", "onblur", "HTMLParagraphElement", "HTMLFieldSetElement", "ondrop", "personalbar", "HTMLSelectElement", "OverflowEvent", "XPathException", "oncanplaythrough", "ProgressEvent", "status", "onselect", "onpause", "MediaError", "HTMLFrameElement", "CSSRule", "devicePixelRatio", "CSSStyleDeclaration", "WebKitCSSTransformValue", "HTMLTableRowElement", "HTMLDirectoryElement", "Option", "Image", "onloadeddata", "WebKitCSSKeyframesRule", "scrollX", "onwebkittransitionend", "screenY", "onkeypress", "toolbar", "SVGTextContentElement", "HTMLAreaElement", "Event", "screenTop", "Element", "Audio", "DocumentType", "crypto", "UIEvent", "EventException", "defaultStatus", "onwebkitanimationend", "screenX", "SVGTransform", "HTMLHRElement", "CSSImportRule", "defaultstatus", "DocumentFragment", "applicationCache", "CSSPageRule", "onload", "onerror", "XPathEvaluator", "onchange", "MediaList", "console", "onabort", "onbeforeunload", "oninput", "onloadstart", "onmousedown", "onmouseout", "onscroll", "StyleSheet", "CSSValue", "CSSVariablesRule", "DOMImplementation", "Document", "Comment", "Notation", "HTMLDocument", "HTMLDListElement", "HTMLHtmlElement", "HTMLLabelElement", "HTMLLinkElement", "HTMLMetaElement", "HTMLTableCellElement", "HTMLTableColElement", "HTMLTableElement", "WebKitCSSKeyframeRule", "WebKitCSSMatrix", "Clipboard", "XMLSerializer", "XMLHttpRequest", "PluginArray", "ClientRect", "HTMLMediaElement", "HTMLVideoElement", "SVGException", "SVGGradientElement", "SVGPathSeg", "SVGRenderingIntent", "SVGTextPathElement", "Cufon"]
                }
            }
        }

然后,他们根据客户端浏览器格式化堆栈跟踪。 然后将此信息发布到服务器。 最有可能通过跟踪像素。