use unproxy instead of replacing this on the windowprxy

This commit is contained in:
velzie 2024-07-30 13:04:55 -04:00
parent 12b17bc3b4
commit 7289a329c4
No known key found for this signature in database
GPG key ID: 048413F95F0DDE1F
4 changed files with 50 additions and 41 deletions

View file

@ -0,0 +1,49 @@
import { iswindow } from "..";
import { ScramjetClient } from "../client";
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 [self]) {
for (const prop in target) {
try {
if (typeof target[prop] === "function") {
client.RawProxy(target, prop, {
apply(ctx) {
if (ctx.this == client.windowProxy) ctx.this = self;
for (const i in ctx.args) {
if (ctx.args[i] === client.windowProxy)
ctx.args[i] = self.global;
}
},
});
}
} catch (e) {}
}
}
if (!iswindow) return;
for (const target of [
self.Node.prototype,
self.MutationObserver.prototype,
self.document,
]) {
for (const prop in target) {
try {
if (typeof target[prop] === "function") {
client.RawProxy(target, prop, {
apply(ctx) {
for (const i in ctx.args) {
if (ctx.args[i] === client.documentProxy)
ctx.args[i] = self.document;
if (ctx.this === client.documentProxy) ctx.this = self.document;
}
},
});
}
} catch (e) {}
}
}
}