Skip to content

Commit f459523

Browse files
committed
[chrome] move inject script from htmlPostRewrite to getInjectScripts
1 parent 071ef20 commit f459523

File tree

1 file changed

+1
-24
lines changed

1 file changed

+1
-24
lines changed

packages/chrome/src/IsolatedFrame.tsx

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,7 @@ const getInjectScripts: ScramjetInterface["getInjectScripts"] = (
257257
script(config.files.wasm),
258258
script(config.files.all),
259259
script("data:application/javascript;base64," + base64Injected),
260+
script(virtualInjectUrl),
260261
];
261262
};
262263
setInterface({
@@ -349,30 +350,6 @@ function makeController(url: URL): Controller {
349350
cookieJar,
350351
prefix: prefix,
351352
});
352-
fetchHandler.addEventListener("htmlPostRewrite", (e: any) => {
353-
const handler = e.handler as DomHandler;
354-
function findhead(node: Element): Element | null {
355-
if (node.type === ElementType.Tag && node.name === "head") {
356-
return node as Element;
357-
} else if (node.childNodes) {
358-
for (const child of node.childNodes) {
359-
const head = findhead(child as Element);
360-
if (head) return head;
361-
}
362-
}
363-
364-
return null;
365-
}
366-
367-
const head = findhead(handler.root as Node as Element)!;
368-
369-
// inject after the scramjet scripts and before the rest of the page
370-
head.children.splice(
371-
3,
372-
0,
373-
new Element("script", { src: virtualInjectUrl })
374-
);
375-
});
376353

377354
const controller = {
378355
controllerframe: frame,

0 commit comments

Comments
 (0)