diff --git a/src/client/client.ts b/src/client/client.ts index 1555d99..cef1ed4 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -10,8 +10,8 @@ import { BareClient, CookieStore, config, - decodeUrl, - encodeUrl, + unrewriteUrl, + rewriteUrl, } from "../shared"; import type BareClientType from "@mercuryworkshop/bare-mux"; import { createWrapFn } from "./shared/wrap"; @@ -199,7 +199,7 @@ export class ScramjetClient { } get url(): URL { - return new URL(decodeUrl(this.global.location.href)); + return new URL(unrewriteUrl(this.global.location.href)); } set url(url: URL | string) { @@ -211,7 +211,7 @@ export class ScramjetClient { } if (ev.defaultPrevented) return; - this.global.location.href = encodeUrl(ev.url, this.meta); + this.global.location.href = rewriteUrl(ev.url, this.meta); } // below are the utilities for proxying and trapping dom APIs diff --git a/src/client/document.ts b/src/client/document.ts index 0712819..c05f179 100644 --- a/src/client/document.ts +++ b/src/client/document.ts @@ -1,4 +1,4 @@ -import { encodeUrl } from "../shared/rewriters/url"; +import { rewriteUrl } from "../shared"; import { ScramjetClient } from "./client"; import { getOwnPropertyDescriptorHandler } from "./helpers"; @@ -22,7 +22,7 @@ export function createDocumentProxy( }, set(target, prop, newValue) { if (prop === "location") { - location.href = encodeUrl(newValue, client.meta); + location.href = rewriteUrl(newValue, client.meta); return; } diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index 6895634..c56cb35 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -1,9 +1,9 @@ import { SCRAMJETCLIENT } from "../../symbols"; import { ScramjetClient } from "../client"; import { nativeGetOwnPropertyDescriptor } from "../natives"; -import { decodeUrl, htmlRules, unrewriteHtml } from "../../shared"; +import { unrewriteUrl, htmlRules, unrewriteHtml } from "../../shared"; import { - encodeUrl, + rewriteUrl, rewriteCss, rewriteHtml, rewriteJs, @@ -57,7 +57,7 @@ export default function (client: ScramjetClient, self: typeof window) { Object.defineProperty(element.prototype, attr, { get() { if (["src", "data", "href", "action", "formaction"].includes(attr)) { - return decodeUrl(descriptor.get.call(this)); + return unrewriteUrl(descriptor.get.call(this)); } return descriptor.get.call(this); @@ -74,7 +74,7 @@ export default function (client: ScramjetClient, self: typeof window) { let origin = new URL(value.substring("blob:".length)); value = "blob:" + location.origin + origin.pathname; } else { - value = encodeUrl(value, client.meta); + value = rewriteUrl(value, client.meta); } } else if (attr === "srcdoc") { value = rewriteHtml( @@ -117,7 +117,7 @@ export default function (client: ScramjetClient, self: typeof window) { const href = desc.get.call(ctx.this); if (!href) return href; - const url = new URL(decodeUrl(href)); + const url = new URL(unrewriteUrl(href)); return url[prop]; }, diff --git a/src/client/dom/history.ts b/src/client/dom/history.ts index 5593994..37ece22 100644 --- a/src/client/dom/history.ts +++ b/src/client/dom/history.ts @@ -1,11 +1,11 @@ import { ScramjetClient } from "../client"; -import { encodeUrl } from "../../shared"; +import { rewriteUrl } from "../../shared"; import { UrlChangeEvent } from "../events"; export default function (client: ScramjetClient, self: typeof globalThis) { client.Proxy("history.pushState", { apply(ctx) { - if (ctx.args[2]) ctx.args[2] = encodeUrl(ctx.args[2], client.meta); + if (ctx.args[2]) ctx.args[2] = rewriteUrl(ctx.args[2], client.meta); ctx.call(); const ev = new UrlChangeEvent(client.url.href); @@ -15,7 +15,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) { client.Proxy("history.replaceState", { apply(ctx) { - if (ctx.args[2]) ctx.args[2] = encodeUrl(ctx.args[2], client.meta); + if (ctx.args[2]) ctx.args[2] = rewriteUrl(ctx.args[2], client.meta); ctx.call(); const ev = new UrlChangeEvent(client.url.href); diff --git a/src/client/dom/open.ts b/src/client/dom/open.ts index 3ad0bdb..ef6d3c2 100644 --- a/src/client/dom/open.ts +++ b/src/client/dom/open.ts @@ -1,11 +1,11 @@ -import { encodeUrl } from "../../shared"; +import { rewriteUrl } from "../../shared"; import { ScramjetClient } from "../client"; import { SCRAMJETCLIENT } from "../../symbols"; export default function (client: ScramjetClient) { client.Proxy("window.open", { apply(ctx) { - if (ctx.args[0]) ctx.args[0] = encodeUrl(ctx.args[0], client.meta); + if (ctx.args[0]) ctx.args[0] = rewriteUrl(ctx.args[0], client.meta); if (["_parent", "_top", "_unfencedTop"].includes(ctx.args[1])) ctx.args[1] = "_self"; diff --git a/src/client/dom/origin.ts b/src/client/dom/origin.ts index d883105..3f2c124 100644 --- a/src/client/dom/origin.ts +++ b/src/client/dom/origin.ts @@ -1,5 +1,5 @@ import { ScramjetClient } from "../client"; -import { decodeUrl } from "../../shared"; +import { unrewriteUrl } from "../../shared"; export default function (client: ScramjetClient, self: typeof window) { client.Trap("origin", { diff --git a/src/client/dom/performance.ts b/src/client/dom/performance.ts index 0c5a377..fce56e5 100644 --- a/src/client/dom/performance.ts +++ b/src/client/dom/performance.ts @@ -1,9 +1,10 @@ -import { decodeUrl } from "../../shared"; +import { unrewriteUrl } from "../../shared"; +import { ScramjetClient } from "../client"; export default function (client: ScramjetClient, self: typeof globalThis) { client.Trap("PerformanceEntry.prototype.name", { get(ctx) { - return decodeUrl(ctx.get()); + return unrewriteUrl(ctx.get() as string); }, }); } diff --git a/src/client/dom/serviceworker.ts b/src/client/dom/serviceworker.ts index 0160305..a31882a 100644 --- a/src/client/dom/serviceworker.ts +++ b/src/client/dom/serviceworker.ts @@ -1,4 +1,4 @@ -import { config, encodeUrl } from "../../shared"; +import { config, rewriteUrl } from "../../shared"; import { ScramjetClient } from "../client"; import { type MessageC2W } from "../../worker"; import { getOwnPropertyDescriptorHandler } from "../helpers"; @@ -61,7 +61,7 @@ export default function (client: ScramjetClient, self: Self) { client.Proxy("navigator.serviceWorker.register", { apply(ctx) { if (ctx.args[0] instanceof URL) ctx.args[0] = ctx.args[0].href; - let url = encodeUrl(ctx.args[0], client.meta) + "?dest=serviceworker"; + let url = rewriteUrl(ctx.args[0], client.meta) + "?dest=serviceworker"; if (ctx.args[1] && ctx.args[1].type === "module") { url += "&type=module"; } diff --git a/src/client/location.ts b/src/client/location.ts index 67c1cc4..bf912db 100644 --- a/src/client/location.ts +++ b/src/client/location.ts @@ -1,7 +1,7 @@ // @ts-nocheck import { ScramjetClient } from "./client"; import { nativeGetOwnPropertyDescriptor } from "./natives"; -import { decodeUrl, encodeUrl } from "../shared"; +import { unrewriteUrl, rewriteUrl } from "../shared"; import { iswindow } from "."; export function createLocationProxy( @@ -77,7 +77,7 @@ export function createLocationProxy( if (self.location.assign) fakeLocation.assign = new Proxy(self.location.assign, { apply(target, thisArg, args) { - args[0] = encodeUrl(args[0], client.meta); + args[0] = rewriteUrl(args[0], client.meta); Reflect.apply(target, self.location, args); }, }); @@ -90,7 +90,7 @@ export function createLocationProxy( if (self.location.replace) fakeLocation.replace = new Proxy(self.location.replace, { apply(target, thisArg, args) { - args[0] = encodeUrl(args[0], client.meta); + args[0] = rewriteUrl(args[0], client.meta); Reflect.apply(target, self.location, args); }, }); diff --git a/src/client/shared/error.ts b/src/client/shared/error.ts index 7d6263c..3ae407a 100644 --- a/src/client/shared/error.ts +++ b/src/client/shared/error.ts @@ -1,4 +1,4 @@ -import { config, decodeUrl } from "../../shared"; +import { config, unrewriteUrl } from "../../shared"; import { ScramjetClient } from "../client"; export const enabled = () => self.$scramjet.config.flags.cleanerrors; @@ -20,7 +20,7 @@ export default function (client: ScramjetClient, _self: Self) { } try { - newstack = newstack.replaceAll(url, decodeUrl(url)); + newstack = newstack.replaceAll(url, unrewriteUrl(url)); } catch {} } diff --git a/src/client/shared/import.ts b/src/client/shared/import.ts index 545923d..02921e2 100644 --- a/src/client/shared/import.ts +++ b/src/client/shared/import.ts @@ -1,6 +1,6 @@ import { ScramjetClient } from "../client"; import { config } from "../../shared"; -import { encodeUrl } from "../../shared/rewriters/url"; +import { rewriteUrl } from "../../shared/rewriters/url"; export default function (client: ScramjetClient, self: Self) { const Function = client.natives.Function; @@ -9,7 +9,9 @@ export default function (client: ScramjetClient, self: Self) { return function (url: string) { const resolved = new URL(url, base).href; - return Function(`return import("${encodeUrl(resolved, client.meta)}")`)(); + return Function( + `return import("${rewriteUrl(resolved, client.meta)}")` + )(); }; }; diff --git a/src/client/shared/requests/beacon.ts b/src/client/shared/requests/beacon.ts index 47bd05e..f758521 100644 --- a/src/client/shared/requests/beacon.ts +++ b/src/client/shared/requests/beacon.ts @@ -1,10 +1,10 @@ -import { encodeUrl } from "../../../shared/rewriters/url"; +import { rewriteUrl } from "../../../shared"; import { ScramjetClient } from "../../client"; export default function (client: ScramjetClient, self) { client.Proxy("navigator.sendBeacon", { apply(ctx) { - ctx.args[0] = encodeUrl(ctx.args[0], client.meta); + ctx.args[0] = rewriteUrl(ctx.args[0], client.meta); }, }); } diff --git a/src/client/shared/requests/eventsource.ts b/src/client/shared/requests/eventsource.ts index 0390c88..a8399cc 100644 --- a/src/client/shared/requests/eventsource.ts +++ b/src/client/shared/requests/eventsource.ts @@ -1,16 +1,16 @@ -import { decodeUrl, encodeUrl } from "../../../shared"; +import { unrewriteUrl, rewriteUrl } from "../../../shared"; import { ScramjetClient } from "../../client"; export default function (client: ScramjetClient) { client.Proxy("EventSource", { construct(ctx) { - ctx.args[0] = encodeUrl(ctx.args[0], client.meta); + ctx.args[0] = rewriteUrl(ctx.args[0], client.meta); }, }); client.Trap("EventSource.prototype.url", { get(ctx) { - decodeUrl(ctx.get() as string); + unrewriteUrl(ctx.get() as string); }, }); } diff --git a/src/client/shared/requests/fetch.ts b/src/client/shared/requests/fetch.ts index 9719817..f6756c0 100644 --- a/src/client/shared/requests/fetch.ts +++ b/src/client/shared/requests/fetch.ts @@ -1,15 +1,15 @@ // ts throws an error if you dont do window.fetch import { isemulatedsw } from "../.."; -import { decodeUrl } from "../../../shared/rewriters/url"; +import { unrewriteUrl } from "../../../shared"; import { ScramjetClient } from "../../client"; -import { encodeUrl, rewriteHeaders } from "../../../shared"; +import { rewriteUrl, rewriteHeaders } from "../../../shared"; export default function (client: ScramjetClient, self: typeof globalThis) { client.Proxy("fetch", { apply(ctx) { if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) { - ctx.args[0] = encodeUrl(ctx.args[0].toString(), client.meta); + ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta); if (isemulatedsw) ctx.args[0] += "?from=swruntime"; } @@ -25,7 +25,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) { client.Proxy("Request", { construct(ctx) { if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) { - ctx.args[0] = encodeUrl(ctx.args[0].toString(), client.meta); + ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta); if (isemulatedsw) ctx.args[0] += "?from=swruntime"; } @@ -34,13 +34,13 @@ export default function (client: ScramjetClient, self: typeof globalThis) { client.Trap("Response.prototype.url", { get(ctx) { - return decodeUrl(ctx.get() as string); + return unrewriteUrl(ctx.get() as string); }, }); client.Trap("Request.prototype.url", { get(ctx) { - return decodeUrl(ctx.get() as string); + return unrewriteUrl(ctx.get() as string); }, }); diff --git a/src/client/shared/requests/xmlhttprequest.ts b/src/client/shared/requests/xmlhttprequest.ts index 6af7e71..d6cd371 100644 --- a/src/client/shared/requests/xmlhttprequest.ts +++ b/src/client/shared/requests/xmlhttprequest.ts @@ -1,4 +1,4 @@ -import { config, decodeUrl, encodeUrl } from "../../../shared"; +import { config, unrewriteUrl, rewriteUrl } from "../../../shared"; import { ScramjetClient } from "../../client"; let nativeworker; let postmessage; @@ -18,7 +18,7 @@ export default function (client: ScramjetClient, self: Self) { client.Proxy("XMLHttpRequest.prototype.open", { apply(ctx) { - if (ctx.args[1]) ctx.args[1] = encodeUrl(ctx.args[1], client.meta); + if (ctx.args[1]) ctx.args[1] = rewriteUrl(ctx.args[1], client.meta); ctx.this[ARGS] = ctx.args; }, }); @@ -128,7 +128,7 @@ export default function (client: ScramjetClient, self: Self) { client.Trap("XMLHttpRequest.prototype.responseURL", { get(ctx) { - return decodeUrl(ctx.get() as string); + return unrewriteUrl(ctx.get() as string); }, }); } diff --git a/src/client/shared/worker.ts b/src/client/shared/worker.ts index cc74b34..a6e10c8 100644 --- a/src/client/shared/worker.ts +++ b/src/client/shared/worker.ts @@ -1,6 +1,6 @@ import { iswindow } from ".."; import { BareMuxConnection } from "../../shared"; -import { encodeUrl } from "../../shared/rewriters/url"; +import { rewriteUrl } from "../../shared"; import type { MessageC2W } from "../../worker"; import { ScramjetClient } from "../client"; @@ -14,7 +14,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) { construct({ args, call }) { if (args[0] instanceof URL) args[0] = args[0].href; - args[0] = encodeUrl(args[0], client.meta) + "?dest=worker"; + args[0] = rewriteUrl(args[0], client.meta) + "?dest=worker"; if (args[1] && args[1].type === "module") { args[0] += "&type=module"; @@ -56,7 +56,7 @@ export default function (client: ScramjetClient, self: typeof globalThis) { if (iswindow) { client.Proxy("Worklet.prototype.addModule", { apply(ctx) { - if (ctx.args[0]) ctx.args[0] = encodeUrl(ctx.args[0], client.meta); + if (ctx.args[0]) ctx.args[0] = rewriteUrl(ctx.args[0], client.meta); }, }); diff --git a/src/client/swruntime.ts b/src/client/swruntime.ts index 6921ff2..6b21b2c 100644 --- a/src/client/swruntime.ts +++ b/src/client/swruntime.ts @@ -1,5 +1,5 @@ import { ScramjetClient } from "./client"; -import { decodeUrl } from "../shared"; +import { unrewriteUrl } from "../shared"; export class ScramjetServiceWorkerRuntime { recvport: MessagePort; @@ -72,7 +72,7 @@ function handleMessage( const request = data.scramjet$request; const Request = client.natives["Request"]; - const fakeRequest = new Request(decodeUrl(request.url), { + const fakeRequest = new Request(unrewriteUrl(request.url), { body: request.body, headers: new Headers(request.headers), method: request.method, diff --git a/src/client/worker/importScripts.ts b/src/client/worker/importScripts.ts index 04a0977..e6fef9c 100644 --- a/src/client/worker/importScripts.ts +++ b/src/client/worker/importScripts.ts @@ -1,11 +1,11 @@ -import { encodeUrl } from "../../shared"; +import { rewriteUrl } from "../../shared"; import { ScramjetClient } from "../client"; export default function (client: ScramjetClient, _self: Self) { client.Proxy("importScripts", { apply(ctx) { for (const i in ctx.args) { - ctx.args[i] = encodeUrl(ctx.args[i], client.meta); + ctx.args[i] = rewriteUrl(ctx.args[i], client.meta); } }, }); diff --git a/src/shared.ts b/src/shared.ts index 63ccfa0..ec4b8d1 100644 --- a/src/shared.ts +++ b/src/shared.ts @@ -1,6 +1,6 @@ export const { util: { BareClient, ScramjetHeaders, BareMuxConnection }, - url: { encodeUrl, decodeUrl }, + url: { rewriteUrl, unrewriteUrl }, rewrite: { rewriteCss, unrewriteCss, diff --git a/src/shared/index.ts b/src/shared/index.ts index 347ad2e..f1096b6 100644 --- a/src/shared/index.ts +++ b/src/shared/index.ts @@ -1,4 +1,4 @@ -import { encodeUrl, decodeUrl } from "./rewriters/url"; +import { rewriteUrl, unrewriteUrl } from "./rewriters/url"; import { rewriteCss, unrewriteCss } from "./rewriters/css"; import { rewriteHtml, rewriteSrcset } from "./rewriters/html"; import { rewriteJs } from "./rewriters/js"; @@ -18,8 +18,8 @@ self.$scramjet.shared = { ScramjetHeaders, }, url: { - encodeUrl, - decodeUrl, + rewriteUrl, + unrewriteUrl, }, rewrite: { rewriteCss, diff --git a/src/shared/rewriters/css.ts b/src/shared/rewriters/css.ts index a5b1975..b09668a 100644 --- a/src/shared/rewriters/css.ts +++ b/src/shared/rewriters/css.ts @@ -1,7 +1,7 @@ // This CSS rewriter uses code from Meteor // You can find the original source code at https://github.com/MeteorProxy/Meteor -import { URLMeta, encodeUrl, decodeUrl } from "./url"; +import { URLMeta, rewriteUrl, unrewriteUrl } from "./url"; export function rewriteCss(css: string, meta: URLMeta) { const regex = @@ -18,7 +18,7 @@ export function rewriteCss(css: string, meta: URLMeta) { importContent ) => { const url = urlContent || importContent; - const encodedUrl = encodeUrl(url.trim(), meta); + const encodedUrl = rewriteUrl(url.trim(), meta); if (importStatement) { return `@import url(${urlQuote}${encodedUrl}${urlQuote})`; @@ -48,7 +48,7 @@ export function unrewriteCss(css: string) { importContent ) => { const url = urlContent || importContent; - const encodedUrl = decodeUrl(url.trim()); + const encodedUrl = unrewriteUrl(url.trim()); if (importStatement) { return `@import url(${urlQuote}${encodedUrl}${urlQuote})`; diff --git a/src/shared/rewriters/headers.ts b/src/shared/rewriters/headers.ts index c686f38..738f155 100644 --- a/src/shared/rewriters/headers.ts +++ b/src/shared/rewriters/headers.ts @@ -1,6 +1,6 @@ // TODO this whole file should be inlined and deleted it's a weird relic from ssd era -import { URLMeta, encodeUrl } from "./url"; +import { URLMeta, rewriteUrl } from "./url"; import { BareHeaders } from "@mercuryworkshop/bare-mux"; const cspHeaders = [ "cross-origin-embedder-policy", @@ -27,7 +27,7 @@ const cspHeaders = [ const urlHeaders = ["location", "content-location", "referer"]; function rewriteLinkHeader(link: string, meta: URLMeta) { - return link.replace(/<(.*)>/gi, (match) => encodeUrl(match, meta)); + return link.replace(/<(.*)>/gi, (match) => rewriteUrl(match, meta)); } export function rewriteHeaders(rawHeaders: BareHeaders, meta: URLMeta) { @@ -43,7 +43,7 @@ export function rewriteHeaders(rawHeaders: BareHeaders, meta: URLMeta) { urlHeaders.forEach((header) => { if (headers[header]) - headers[header] = encodeUrl(headers[header]?.toString() as string, meta); + headers[header] = rewriteUrl(headers[header]?.toString() as string, meta); }); if (typeof headers["link"] === "string") { diff --git a/src/shared/rewriters/html.ts b/src/shared/rewriters/html.ts index 010aa62..d0f6e30 100644 --- a/src/shared/rewriters/html.ts +++ b/src/shared/rewriters/html.ts @@ -1,7 +1,7 @@ import { ElementType, Parser } from "htmlparser2"; import { ChildNode, DomHandler, Element } from "domhandler"; import render from "dom-serializer"; -import { URLMeta, encodeUrl } from "./url"; +import { URLMeta, rewriteUrl } from "./url"; import { rewriteCss } from "./css"; import { rewriteJs } from "./js"; import { CookieStore } from "../cookie"; @@ -109,7 +109,7 @@ export const htmlRules: { }[] = [ { fn: (value: string, meta: URLMeta) => { - return encodeUrl(value, meta); + return rewriteUrl(value, meta); }, // url rewrites @@ -238,7 +238,7 @@ function traverseParsedHtml( ) { const contentArray = node.attribs.content.split("url="); if (contentArray[1]) - contentArray[1] = encodeUrl(contentArray[1].trim(), meta); + contentArray[1] = rewriteUrl(contentArray[1].trim(), meta); node.attribs.content = contentArray.join("url="); } } @@ -263,7 +263,7 @@ export function rewriteSrcset(srcset: string, meta: URLMeta) { if (!sufixes) return ""; const rewrittenUrls = urls.map((url, i) => { if (url && sufixes[i]) { - return encodeUrl(url, meta) + sufixes[i]; + return rewriteUrl(url, meta) + sufixes[i]; } }); diff --git a/src/shared/rewriters/url.ts b/src/shared/rewriters/url.ts index 83de6e7..183ffc4 100644 --- a/src/shared/rewriters/url.ts +++ b/src/shared/rewriters/url.ts @@ -23,7 +23,7 @@ export function unrewriteBlob(url: string) { return "blob:" + location.origin + blob.pathname; } -export function encodeUrl(url: string | URL, meta: URLMeta) { +export function rewriteUrl(url: string | URL, meta: URLMeta) { if (url instanceof URL) { url = url.href; } @@ -39,7 +39,7 @@ export function encodeUrl(url: string | URL, meta: URLMeta) { } else { let base = meta.base.href; - if (base.startsWith("about:")) base = decodeUrl(self.location.href); // jank!!!!! weird jank!!! + if (base.startsWith("about:")) base = unrewriteUrl(self.location.href); // jank!!!!! weird jank!!! return ( location.origin + @@ -49,7 +49,7 @@ export function encodeUrl(url: string | URL, meta: URLMeta) { } } -export function decodeUrl(url: string | URL) { +export function unrewriteUrl(url: string | URL) { if (url instanceof URL) { url = url.href; } diff --git a/src/types.d.ts b/src/types.d.ts index 1dc89fd..f7828b3 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,5 +1,5 @@ import { ScramjetController } from "./controller/index"; -import { encodeUrl, decodeUrl } from "./shared/rewriters/url"; +import { rewriteUrl, unrewriteUrl } from "./shared/rewriters/url"; import { rewriteCss, unrewriteCss } from "./shared/rewriters/css"; import { htmlRules, @@ -55,8 +55,8 @@ declare global { $scramjet: { shared: { url: { - encodeUrl: typeof encodeUrl; - decodeUrl: typeof decodeUrl; + rewriteUrl: typeof rewriteUrl; + unrewriteUrl: typeof unrewriteUrl; }; rewrite: { rewriteCss: typeof rewriteCss; diff --git a/src/worker/fetch.ts b/src/worker/fetch.ts index ef40184..f107422 100644 --- a/src/worker/fetch.ts +++ b/src/worker/fetch.ts @@ -5,8 +5,8 @@ import { FakeServiceWorker } from "./fakesw"; import { CookieStore } from "../shared/cookie"; import { ScramjetHeaders, - decodeUrl, - encodeUrl, + unrewriteUrl, + rewriteUrl, rewriteCss, rewriteHeaders, rewriteHtml, @@ -32,7 +32,7 @@ export async function swfetch( if (urlParam.has("url")) { return Response.redirect( - encodeUrl(urlParam.get("url"), newmeta(new URL(urlParam.get("url")))) + rewriteUrl(urlParam.get("url"), newmeta(new URL(urlParam.get("url")))) ); } @@ -88,7 +88,7 @@ export async function swfetch( }); } - const url = new URL(decodeUrl(requesturl)); + const url = new URL(unrewriteUrl(requesturl)); const activeWorker: FakeServiceWorker | null = this.serviceWorkers.find( (w) => w.origin === url.origin @@ -119,7 +119,7 @@ export async function swfetch( new URL(client.url).pathname.startsWith(self.$scramjet.config.prefix) ) { // TODO: i was against cors emulation but we might actually break stuff if we send full origin/referrer always - const clientURL = new URL(decodeUrl(client.url)); + const clientURL = new URL(unrewriteUrl(client.url)); if (clientURL.toString().includes("youtube.com")) { // console.log(headers); } else { @@ -165,7 +165,7 @@ export async function swfetch( if (!["document", "iframe"].includes(request.destination)) return new Response(undefined, { status: 500 }); - return renderError(err, decodeUrl(request.url)); + return renderError(err, unrewriteUrl(request.url)); } }