fix: refrencing wrong globals in location proxy

This commit is contained in:
Percs 2024-10-05 14:03:51 -05:00
parent 293aeb2956
commit ead9d160a9
2 changed files with 7 additions and 7 deletions

View file

@ -166,8 +166,8 @@ export class ScramjetClient {
const module = context(key);
if (!key.endsWith(".ts")) continue;
if (
(key.startsWith("./dom/") && "window" in self) ||
(key.startsWith("./worker/") && "WorkerGlobalScope" in self) ||
(key.startsWith("./dom/") && "window" in this.global) ||
(key.startsWith("./worker/") && "WorkerGlobalScope" in this.global) ||
key.startsWith("./shared/")
) {
modules.push(module);
@ -189,7 +189,7 @@ export class ScramjetClient {
}
get url(): URL {
return new URL(decodeUrl(self.location.href));
return new URL(decodeUrl(this.global.location.href));
}
set url(url: URL | string) {
@ -201,7 +201,7 @@ export class ScramjetClient {
}
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

View file

@ -14,10 +14,10 @@ export default function (client: ScramjetClient) {
if (!realwin) return ctx.return(realwin);
if (SCRAMJETCLIENT in realwin.self) {
return ctx.return(realwin.self[SCRAMJETCLIENT].globalProxy.window);
if (SCRAMJETCLIENT in realwin) {
return ctx.return(realwin[SCRAMJETCLIENT].globalProxy.window);
} else {
const newclient = new ScramjetClient(realwin.self);
const newclient = new ScramjetClient(realwin);
// hook the opened window
newclient.hook();