Window.onerror error monitoring, send to background

Source: Internet
Author: User

var doc = Document.body | | Document.documentelement;var _onerror = onerror ("); var onerror = function (URL) {this.init (URL);}    Onerror.prototype.init = function (URL) {this.url = Url;this.system = This._system ();    This.browser = This._browser ();    This.host = Location.host;    This.referrer = Document.referrer; This.path = Location.pathname;} Onerror.prototype._system = function () {return Navigator.platform | | "Unknow"; }onerror.prototype._browser = function () {return Navigator.useragent | | "Unknow";};o    Nerror.prototype.catchError = function (DES, path, line, Word) {if (!des) return false; Return This.request ({description:des, File:PATH, Line:line, Word:word});};o    nerror.prototype.request = function (URL, options) {var = this; var default_settings = {"Host": Self.host, "referrer": Self.referrer, "path": Self.path, " Timestamp ": +new Date," system ": Self.system," browser ": Self. Browser, "language": Self.language}; Beacon uses the Post method//img_beacon this[(Issupportbeacon && openbeacon) using get mode? "_beacon": "_img_beacon"] (URL, $.extend (default_settings, Options));};o Nerror.prototype._beacon = function (URL, options) {return Navigator.sendbeacon (URL, json.stringify (options));};o   Nerror.prototype._img_beacon = function (URL, options) {var img = new Image ();   IMG.SRC = URL + "?" + object2urlstring (options);   Img.onload = function () {}; Return Doc.appendchild (IMG);};    function object2urlstring (obj) {var r = [];    for (var i in obj) {R.push (i + "=" + Obj[i]); } return R.join ("&");} Window.onerror = function () {return _onerror.catcherror (arguments);};

Node Express code

Router.get ('/window-onerror/error.gif ', function (req, res, next) {  var $req = getData (req),            data = $req. result,            Isbeacon = $req. Isbeacon;        if (!DATA.UTMB) {            return this.res.end ();        }        Insert Database        console.log (data);        Beacon does not need return value        if (isbeacon) {            return res.end ();        }        IMG Beacon        Else {            //Set HTTP request header to Image/gif            res.writehead (' $ ', {' Content-type ': ' Image/gif '});            1x1 gif is the return value returned            res.end (' ivborw0kggoaaaansuheugaaaaeaaaabcayaaaaffcsjaaaaduleqvqimwngygbgaaaabqabh6fo1aaaaabjru5erkjggg== ', ' base64 ');}        );

  

Window.onerror error monitoring, send to background

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.