Cc-Edit / Vue-dataAc

Vue 前端数据采集插件,前端异常数据采集插件,用户行为监控采集插件,用户前端异常监控插件,图形化分析插件(附demo)如有帮助请star😊
https://data.ccedit.com
112 stars 30 forks source link

axios 请求接口XMLRequest拦截 无响应 #9

Open ichangjun opened 3 years ago

ichangjun commented 3 years ago
/**
 *初始化请求劫持
 * */
VueDataAc.prototype._initXhrErrAc = function _initXhrErrAc () {
  const _nativeAjaxOpen = XMLHttpRequest.prototype.open;
  const _nativeAjaxSend = XMLHttpRequest.prototype.send;
  const _nativeAjaxonReady = XMLHttpRequest.onreadystatechange;
  this._proxyXhrObj = {
    open: function () {
      this._ac_method = (arguments[0] || [])[0];
      return (_nativeAjaxOpen && _nativeAjaxOpen.apply(this, arguments));
    },
    send: function () {
      this._ac_send_time = ac_util_getTime().timeStamp;
      this._ac_post_data = (arguments[0] || [])[0] || '';
      this.addEventListener('error', function (xhr) {
        _VueDataAc._formatXhrErrorData(xhr.target);
      });
      this.onreadystatechange = function (xhr) {
        _VueDataAc._formatXhrErrorData(xhr.target);
        _nativeAjaxonReady && _nativeAjaxonReady.apply(this, arguments);
      };
      return (_nativeAjaxSend && _nativeAjaxSend.apply(this, arguments));
    }
  };
  XMLHttpRequest.prototype.open = this._proxyXhrObj.open;
  XMLHttpRequest.prototype.send = this._proxyXhrObj.send;
};