mirror of
https://github.com/MercuryWorkshop/scramjet.git
synced 2025-05-13 14:30:02 -04:00
fix dummy serviceworker methods
This commit is contained in:
parent
1a98345d9e
commit
dad6cf1371
3 changed files with 23 additions and 4 deletions
|
@ -175,6 +175,8 @@ export default function (client: ScramjetClient, self: typeof window) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// an automated approach to cleaning the documentProxy from dom functions
|
||||||
|
// it will trigger an illegal invocation if you pass the proxy to c++ code, we gotta hotswap it out with the real one
|
||||||
for (const target of [
|
for (const target of [
|
||||||
self.Node.prototype,
|
self.Node.prototype,
|
||||||
self.MutationObserver.prototype,
|
self.MutationObserver.prototype,
|
||||||
|
|
|
@ -2,12 +2,32 @@ import { encodeUrl } from "../../shared/rewriters/url";
|
||||||
import { ScramjetClient } from "../client";
|
import { ScramjetClient } from "../client";
|
||||||
|
|
||||||
export default function (client: ScramjetClient, self: Self) {
|
export default function (client: ScramjetClient, self: Self) {
|
||||||
|
let fakeregistrations = new WeakSet();
|
||||||
|
|
||||||
client.Proxy("Worklet.prototype.addModule", {
|
client.Proxy("Worklet.prototype.addModule", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
ctx.args[0] = encodeUrl(ctx.args[0]);
|
ctx.args[0] = encodeUrl(ctx.args[0]);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
client.Proxy("addEventListener", {
|
||||||
|
apply(ctx) {
|
||||||
|
if (fakeregistrations.has(ctx.this)) {
|
||||||
|
// do nothing
|
||||||
|
ctx.return(undefined);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
client.Proxy("removeEventListener", {
|
||||||
|
apply(ctx) {
|
||||||
|
if (fakeregistrations.has(ctx.this)) {
|
||||||
|
// do nothing
|
||||||
|
ctx.return(undefined);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
client.Proxy("navigator.serviceWorker.register", {
|
client.Proxy("navigator.serviceWorker.register", {
|
||||||
apply(ctx) {
|
apply(ctx) {
|
||||||
if (ctx.args[0] instanceof URL) ctx.args[0] = ctx.args[0].href;
|
if (ctx.args[0] instanceof URL) ctx.args[0] = ctx.args[0].href;
|
||||||
|
@ -54,6 +74,7 @@ export default function (client: ScramjetClient, self: Self) {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
fakeregistrations.add(fakeRegistration);
|
||||||
|
|
||||||
ctx.return(new Promise((resolve) => resolve(fakeRegistration)));
|
ctx.return(new Promise((resolve) => resolve(fakeRegistration)));
|
||||||
},
|
},
|
||||||
|
|
|
@ -9,10 +9,6 @@ export default function (client: ScramjetClient, self: typeof globalThis) {
|
||||||
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
if (typeof ctx.args[0] === "string" || ctx.args[0] instanceof URL) {
|
||||||
ctx.args[0].toString();
|
ctx.args[0].toString();
|
||||||
ctx.args[0] = encodeUrl(ctx.args[0].toString());
|
ctx.args[0] = encodeUrl(ctx.args[0].toString());
|
||||||
} else if (ctx.args[0] instanceof Request && ctx.args[0].url) {
|
|
||||||
Object.defineProperty(ctx.args[0], "url", {
|
|
||||||
value: encodeUrl(ctx.args[0].url),
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue