Skip to content

Commit ff541e8

Browse files
committed
fix(pat-inject): Re-insert all script tags from the source so that they are executed. Otherwise they're not run nor is the script src downloaded.
1 parent 1d5c231 commit ff541e8

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/pat/inject/inject.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,9 +819,23 @@ const inject = {
819819
elementbefore: "before",
820820
}[cfg.action];
821821

822-
// Inject the content HERE!
823822
target[method](...source_nodes);
824823

824+
if (! cfg.removeTags?.includes("script")) {
825+
// Find and execute scripts
826+
for (const node of source_nodes) {
827+
const scripts = node.querySelectorAll?.("script") || [];
828+
for (const script of scripts) {
829+
const new_script = document.createElement("script");
830+
for (const attr of [...script.attributes]) {
831+
new_script.setAttribute(attr.name, attr.value)
832+
}
833+
new_script.textContent = script.textContent;
834+
script.replaceWith(new_script);
835+
}
836+
}
837+
}
838+
825839
return true;
826840
},
827841

0 commit comments

Comments
 (0)