// ==UserScript== // @name XHR劫持返回内容例子 // @namespace http://tampermonkey.net/ // @version 0.1 // @description try to take over the world! // @author You // @match http://127.0.0.1:8000/1.html // @icon https://www.google.com/s2/favicons?domain=undefined. // @grant none // ==/UserScript== var oldxhr=window.XMLHttpRequest function newobj(){} window.XMLHttpRequest=function(){ let tagetobk=new newobj(); tagetobk.oldxhr=new oldxhr(); let handle={ get: function(target, prop, receiver) { if(prop==='oldxhr'){ return Reflect.get(target,prop); } if(typeof Reflect.get(target.oldxhr,prop)==='function') { if(Reflect.get(target.oldxhr,prop+'proxy')===undefined) { target.oldxhr[prop+'proxy']=new Proxy(Reflect.get(target.oldxhr,prop), { apply: function(target, thisArg, argumentsList) { debugger; return Reflect.apply(target, thisArg.oldxhr, argumentsList); } }); } return Reflect.get(target.oldxhr,prop+'proxy') } if(prop.indexOf('response')!==-1) { console.log('我们劫持成功了!',Reflect.get(target.oldxhr,prop)) return 'FFFFFFFFUCK' } return Reflect.get(target.oldxhr,prop); }, set(target, prop, value) { return Reflect.set(target.oldxhr, prop, value); }, has(target, key) { debugger; return Reflect.has(target.oldxhr,key); } } let ret = new Proxy(tagetobk, handle); return ret; }