zoukankan      html  css  js  c++  java
  • js 监听ajax请求

    function hookSend(hook) {
      if (!XMLHttpRequest.prototype._oldSend)
        XMLHttpRequest.prototype._oldSend = XMLHttpRequest.prototype.send;
      XMLHttpRequest.prototype.send = function () {
        if (hook && typeof hook === "function") hook([...arguments], this);
        return this._oldSend(...arguments);
      };
    }
    
    hookSend((a,c) => {
      console.log("args: %o, this: %o", a, c)
    })
    

    监听你的send是否被挂钩

    const _oldSend = XMLHttpRequest.prototype.send;
    Object.defineProperty(XMLHttpRequest.prototype, "send", {
      set: function (v) {
        console.log("[XHR] set send!!!");
      },
      get: function () {
        return _oldSend;
      },
    });
    

    你可能还需要保护所有检测函数,避免被挂钩。

  • 相关阅读:
    四十八.监控概述 、 Zabbix基础 、 Zabbix监控服务
    123D
    bzoj3879
    bzoj1699
    LA6878
    uoj#149
    687C
    codeforces round #424 div2
    803E
    713C
  • 原文地址:https://www.cnblogs.com/ajanuw/p/13775888.html
Copyright © 2011-2022 走看看