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) + }); + } }, });