From 3b277923253ab7af82ee15d18f5e56aec3a75716 Mon Sep 17 00:00:00 2001 From: Avad3 <65318266+Avad3@users.noreply.github.com> Date: Wed, 26 Jun 2024 14:28:00 -0400 Subject: [PATCH] add xmlhttprequest support --- src/client/index.ts | 7 ++++--- src/client/xmlhttprequest.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 src/client/xmlhttprequest.ts diff --git a/src/client/index.ts b/src/client/index.ts index fbc945b..82fe926 100644 --- a/src/client/index.ts +++ b/src/client/index.ts @@ -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; } -} \ No newline at end of file +} diff --git a/src/client/xmlhttprequest.ts b/src/client/xmlhttprequest.ts new file mode 100644 index 0000000..eaedded --- /dev/null +++ b/src/client/xmlhttprequest.ts @@ -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); + }, +});