fix: misc bugs

This commit is contained in:
Percs 2024-11-26 23:10:44 -06:00
parent 58fed66f78
commit ca3e09af8e
8 changed files with 20 additions and 28 deletions

View file

@ -1,19 +1,6 @@
import { ScramjetClient } from "../client";
import { rewriteCss, unrewriteCss } from "../../shared";
// Why is this here?
// const cssProperties = [
// "background",
// "background-image",
// "mask",
// "mask-image",
// "list-style",
// "list-style-image",
// "border-image",
// "border-image-source",
// "cursor",
// ];
export default function (client: ScramjetClient) {
client.Proxy("CSSStyleDeclaration.prototype.setProperty", {
apply(ctx) {

View file

@ -320,8 +320,8 @@ export default function (client: ScramjetClient, self: typeof window) {
],
{
apply(ctx) {
const document = ctx.call();
if (document) {
const doc = ctx.call();
if (doc) {
ctx.return(ctx.this.contentDocument);
}
},

View file

@ -17,7 +17,7 @@ export default function (client: ScramjetClient, _self: Self) {
client.Proxy("CacheStorage.prototype.match", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
@ -31,7 +31,7 @@ export default function (client: ScramjetClient, _self: Self) {
client.Proxy("Cache.prototype.add", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
@ -43,7 +43,7 @@ export default function (client: ScramjetClient, _self: Self) {
typeof ctx.args[0][i] === "string" ||
ctx.args[0][i] instanceof URL
) {
ctx.args[0][i] = rewriteUrl(ctx.args[0][i].toString(), client.meta);
ctx.args[0][i] = rewriteUrl(ctx.args[0][i], client.meta);
}
}
},
@ -52,7 +52,7 @@ export default function (client: ScramjetClient, _self: Self) {
client.Proxy("Cache.prototype.put", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
@ -60,7 +60,7 @@ export default function (client: ScramjetClient, _self: Self) {
client.Proxy("Cache.prototype.match", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
@ -71,7 +71,7 @@ export default function (client: ScramjetClient, _self: Self) {
(ctx.args[0] && typeof ctx.args[0] === "string") ||
(ctx.args[0] && ctx.args[0] instanceof URL)
) {
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
@ -82,7 +82,7 @@ export default function (client: ScramjetClient, _self: Self) {
(ctx.args[0] && typeof ctx.args[0] === "string") ||
(ctx.args[0] && ctx.args[0] instanceof URL)
) {
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});
@ -90,7 +90,7 @@ export default function (client: ScramjetClient, _self: Self) {
client.Proxy("Cache.prototype.delete", {
apply(ctx) {
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
ctx.args[0] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
}
},
});

View file

@ -20,6 +20,7 @@ export default function (client: ScramjetClient) {
} else if (typeof ctx.args[2] === "object" && ctx.args[2] !== null) {
pollutant = ctx.args[2]; // next try to use transfer
} else if (
ctx.this &&
POLLUTANT in ctx.this &&
typeof ctx.this[POLLUTANT] === "object" &&
ctx.this[POLLUTANT] !== null

View file

@ -9,7 +9,7 @@ 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] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
if (isemulatedsw) ctx.args[0] += "?from=swruntime";
}
@ -19,7 +19,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] = rewriteUrl(ctx.args[0].toString(), client.meta);
ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);
if (isemulatedsw) ctx.args[0] += "?from=swruntime";
}

View file

@ -50,6 +50,10 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
binaryType: "blob",
barews,
onclose: null,
onerror: null,
onmessage: null,
onopen: null,
captureListeners: {},
listeners: {},
};

View file

@ -28,7 +28,7 @@ export function unrewriteBlob(url: string) {
export function rewriteUrl(url: string | URL, meta: URLMeta) {
if (url instanceof URL) {
url = url.href;
url = url.toString();
}
if (url.startsWith("javascript:")) {
@ -58,7 +58,7 @@ export function rewriteUrl(url: string | URL, meta: URLMeta) {
export function unrewriteUrl(url: string | URL) {
if (url instanceof URL) {
url = url.href;
url = url.toString();
}
const prefixed = location.origin + $scramjet.config.prefix;

View file

@ -228,7 +228,7 @@ function BrowserApp() {
const cfg = h(Config);
document.body.appendChild(cfg);
this.githubURL = `https://github.com/MercuryWorkshop/scramjet/tree/${$scramjet.version.build}`;
this.githubURL = `https://github.com/MercuryWorkshop/scramjet/commit/${$scramjet.version.build}`;
return html`
<div>