add xmlhttprequest support

This commit is contained in:
Avad3 2024-06-26 14:28:00 -04:00
parent d4295e902d
commit 3b27792325
2 changed files with 22 additions and 3 deletions

View file

@ -1,12 +1,13 @@
import "./location";
import "./trustedTypes.ts";
import "./eval.ts";
import "./storage";
import "./element.ts";
import "./eval.ts";
import "./fetch.ts";
import "./trustedTypes.ts";
import "./xmlhttprequest.ts";
declare global {
interface Window {
__location: Location;
}
}
}

View file

@ -0,0 +1,18 @@
XMLHttpRequest.prototype.open = new Proxy(XMLHttpRequest.prototype.open, {
apply(target, thisArg, argArray) {
if (argArray[1]) argArray[1] = self.__scramjet$bundle.rewriters.url.encodeUrl(argArray[1]);
return Reflect.apply(target, thisArg, argArray);
},
});
XMLHttpRequest.prototype.setRequestHeader = new Proxy(XMLHttpRequest.prototype.setRequestHeader, {
apply(target, thisArg, argArray) {
let headerObject = Object.fromEntries(argArray);
headerObject = self.__scramjet$bundle.rewriters.rewriteHeaders(headerObject);
argArray = Object.entries(headerObject);
return Reflect.apply(target, thisArg, argArray);
},
});