Skip to content

Instantly share code, notes, and snippets.

@chenbojian
chenbojian / force-xhr-status-with-proxy.js
Created December 23, 2024 12:56 — forked from davidsharp/force-xhr-status-with-proxy.js
Proxying a XMLHttpRequest to force the status received
XMLHttpRequest = new Proxy(XMLHttpRequest, {
construct:function(t,a){
const req = new t();
return new Proxy(req, {
get:function(o,p){
if(p=='status')return 9001
return typeof o[p] == 'function'?o[p].bind(o):o[p]
},
set: function(target, prop, value) {
Reflect.set(target, prop, value) // or target[prop] = value