Skip to content

Commit

Permalink
fix: misc bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
Percslol committed Nov 27, 2024
1 parent 58fed66 commit ca3e09a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 28 deletions.
13 changes: 0 additions & 13 deletions src/client/dom/css.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/client/dom/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
Expand Down
16 changes: 8 additions & 8 deletions src/client/shared/caches.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
},
});
Expand All @@ -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);
}
},
});
Expand All @@ -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);
}
}
},
Expand All @@ -52,15 +52,15 @@ 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);
}
},
});

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);
}
},
});
Expand All @@ -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);
}
},
});
Expand All @@ -82,15 +82,15 @@ 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);
}
},
});

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);
}
},
});
Expand Down
1 change: 1 addition & 0 deletions src/client/shared/postmessage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/client/shared/requests/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
}
Expand All @@ -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";
}
Expand Down
4 changes: 4 additions & 0 deletions src/client/shared/requests/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {},
};
Expand Down
4 changes: 2 additions & 2 deletions src/shared/rewriters/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:")) {
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion static/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit ca3e09a

Please sign in to comment.