Skip to content

Commit 7f36cb8

Browse files
committed
[scramjet] proxy Element.prototype.append/appendChild
1 parent 49bc219 commit 7f36cb8

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

packages/scramjet/src/client/dom/element.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,37 @@ export default function (client: ScramjetClient, self: typeof window) {
418418
} catch {}
419419
},
420420
});
421+
422+
// TODO: this needs to be done for all insert methods
423+
client.Proxy(["Element.prototype.appendChild", "Element.prototype.append"], {
424+
apply(ctx) {
425+
if (ctx.this instanceof self.HTMLStyleElement) {
426+
for (const node of ctx.args) {
427+
if (node instanceof self.Text) {
428+
node.data = rewriteCss(ctx.args[0].data, client.meta);
429+
}
430+
}
431+
} else if (ctx.this instanceof self.HTMLScriptElement) {
432+
for (const node of ctx.args) {
433+
if (node instanceof self.Text) {
434+
const newval: string = rewriteJs(
435+
node.data,
436+
"(anonymous script element)",
437+
client.meta
438+
) as string;
439+
client.natives.call(
440+
"Element.prototype.setAttribute",
441+
ctx.this,
442+
"scramjet-attr-script-source-src",
443+
bytesToBase64(encoder.encode(newval))
444+
);
445+
node.data = newval;
446+
}
447+
}
448+
}
449+
},
450+
});
451+
421452
client.Proxy("Audio", {
422453
construct(ctx) {
423454
if (ctx.args[0]) ctx.args[0] = rewriteUrl(ctx.args[0], client.meta);

0 commit comments

Comments
 (0)