From f9e7fc76d9ad4de24617d5a7eea0cea495052c42 Mon Sep 17 00:00:00 2001 From: Avad3 <65318266+Avad3@users.noreply.github.com> Date: Mon, 29 Jul 2024 22:54:44 -0400 Subject: [PATCH] fix fetch proy --- src/client/shared/requests/fetch.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/client/shared/requests/fetch.ts b/src/client/shared/requests/fetch.ts index 384e38e..249628b 100644 --- a/src/client/shared/requests/fetch.ts +++ b/src/client/shared/requests/fetch.ts @@ -1,11 +1,19 @@ // ts throws an error if you dont do window.fetch +import { ScramjetClient } from "../../client"; import { encodeUrl, rewriteHeaders } from "../../shared"; export default function (client: ScramjetClient, self: typeof globalThis) { client.Proxy("fetch", { apply(ctx) { - ctx.args[0] = encodeUrl(ctx.args[0]); + if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) { + ctx.args[0].toString(); + ctx.args[0] = encodeUrl(ctx.args[0].toString()); + } else if (ctx.args[0] instanceof Request && ctx.args[0].url) { + Object.defineProperty(ctx.args[0], "url", { + value: encodeUrl(ctx.args[0].url) + }); + } }, });