From c2570c1d86f6944d947441036b887a9daf01e44b Mon Sep 17 00:00:00 2001 From: Percs <83934299+Percslol@users.noreply.github.com> Date: Mon, 14 Oct 2024 21:38:36 -0500 Subject: [PATCH] fix: node.getrootnode --- src/client/client.ts | 3 ++- src/client/dom/element.ts | 13 ++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/client/client.ts b/src/client/client.ts index 332b757..e0ab536 100644 --- a/src/client/client.ts +++ b/src/client/client.ts @@ -13,7 +13,7 @@ import { unrewriteUrl, rewriteUrl, } from "../shared"; -import type BareClientType from "@mercuryworkshop/bare-mux"; +import { BareClient as BareClientType } from "@mercuryworkshop/bare-mux"; import { createWrapFn } from "./shared/wrap"; import { NavigateEvent } from "./events"; import type { URLMeta } from "../shared/rewriters/url"; @@ -378,6 +378,7 @@ export class ScramjetClient { return oldDescriptor && oldDescriptor.get.call(this.this); }, set: function (v: T) { + // eslint-disable-next-line @typescript-eslint/no-unused-expressions oldDescriptor && oldDescriptor.set.call(this.this, v); }, }; diff --git a/src/client/dom/element.ts b/src/client/dom/element.ts index 7ec06eb..4cf1dd4 100644 --- a/src/client/dom/element.ts +++ b/src/client/dom/element.ts @@ -306,7 +306,6 @@ export default function (client: ScramjetClient, self: typeof window) { "Node.prototype.parentElement", "Node.prototype.previousSibling", "Node.prototype.nextSibling", - "Node.prototype.getRootNode", ], { get(ctx) { @@ -321,6 +320,18 @@ export default function (client: ScramjetClient, self: typeof window) { } ); + client.Proxy("Node.prototype.getRootNode", { + apply(ctx) { + const n = ctx.call() as Node; + if (!(n instanceof Document)) return ctx.return(n); + + const scram: ScramjetClient = n[SCRAMJETCLIENT]; + if (!scram) return ctx.return(n); // ?? + + return ctx.return(scram.documentProxy); + }, + }); + client.Proxy("DOMParser.prototype.parseFromString", { apply(ctx) { if (ctx.args[1] === "text/html") {