fix client.url using the wrong location

This commit is contained in:
velzie 2024-10-10 18:37:07 -04:00
parent 118610cc99
commit 1dba0f8fa0
2 changed files with 12 additions and 21 deletions

View file

@ -108,7 +108,7 @@ export class ScramjetClient {
resolve(data.port); resolve(data.port);
} }
}); });
}) }),
); );
} }
@ -189,7 +189,7 @@ export class ScramjetClient {
} }
get url(): URL { get url(): URL {
return new URL(decodeUrl(self.location.href)); return new URL(decodeUrl(this.global.location.href));
} }
set url(url: URL | string) { set url(url: URL | string) {
@ -201,7 +201,7 @@ export class ScramjetClient {
} }
if (ev.defaultPrevented) return; if (ev.defaultPrevented) return;
self.location.href = encodeUrl(ev.url, this.meta); this.global.location.href = encodeUrl(ev.url, this.meta);
} }
// below are the utilities for proxying and trapping dom APIs // below are the utilities for proxying and trapping dom APIs
@ -239,7 +239,7 @@ export class ScramjetClient {
h.construct = function ( h.construct = function (
constructor: any, constructor: any,
argArray: any[], argArray: any[],
newTarget: AnyFunction newTarget: AnyFunction,
) { ) {
let returnValue: any = undefined; let returnValue: any = undefined;
let earlyreturn = false; let earlyreturn = false;
@ -354,7 +354,7 @@ export class ScramjetClient {
RawTrap<T>( RawTrap<T>(
target: any, target: any,
prop: string, prop: string,
descriptor: Trap<T> descriptor: Trap<T>,
): PropertyDescriptor { ): PropertyDescriptor {
if (!target) return; if (!target) return;
if (!prop) return; if (!prop) return;

View file

@ -19,29 +19,20 @@ export function encodeUrl(url: string | URL, meta: URLMeta) {
url = url.href; url = url.href;
} }
// if (!origin) {
// if (location.pathname.startsWith(self.$scramjet.config.prefix + "worker")) {
// origin = new URL(new URL(location.href).searchParams.get("origin"));
// } else
// origin = new URL(
// self.$scramjet.codec.decode(
// location.href.slice(
// (location.origin + self.$scramjet.config.prefix).length
// )
// )
// );
// }
if (url.startsWith("javascript:")) { if (url.startsWith("javascript:")) {
return "javascript:" + rewriteJs(url.slice("javascript:".length), meta); return "javascript:" + rewriteJs(url.slice("javascript:".length), meta);
} else if (/^(#|mailto|about|data|blob)/.test(url)) { } else if (/^(#|mailto|about|data|blob)/.test(url)) {
// TODO this regex is jank but i'm not fixing it // TODO this regex is jank but i'm not fixing it
return url; return url;
} else { } else {
let base = meta.base.href;
if (base.startsWith("about:")) base = decodeUrl(self.location.href); // jank!!!!! weird jank!!!
return ( return (
location.origin + location.origin +
self.$scramjet.config.prefix + self.$scramjet.config.prefix +
self.$scramjet.codec.encode(new URL(url, meta.base).href) self.$scramjet.codec.encode(new URL(url, base).href)
); );
} }
} }
@ -54,7 +45,7 @@ export function decodeUrl(url: string | URL) {
if ( if (
tryCanParseURL(url)?.pathname.startsWith( tryCanParseURL(url)?.pathname.startsWith(
self.$scramjet.config.prefix + "worker" self.$scramjet.config.prefix + "worker",
) )
) { ) {
return new URL(new URL(url).searchParams.get("origin")).href; return new URL(new URL(url).searchParams.get("origin")).href;
@ -64,7 +55,7 @@ export function decodeUrl(url: string | URL) {
return url; return url;
} else if (tryCanParseURL(url)) { } else if (tryCanParseURL(url)) {
return self.$scramjet.codec.decode( return self.$scramjet.codec.decode(
url.slice((location.origin + self.$scramjet.config.prefix).length) url.slice((location.origin + self.$scramjet.config.prefix).length),
); );
} else { } else {
return url; return url;