Skip to content

Commit 8bf3917

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 c154bb4 commit 8bf3917

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

src/pat/inject/inject.js

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

830-
// Inject the content HERE!
831830
target[method](...source_nodes);
832831

832+
if (! cfg.removeTags?.includes("script")) {
833+
// Find and execute scripts
834+
for (const node of source_nodes) {
835+
const scripts = node.querySelectorAll?.("script") || [];
836+
for (const script of scripts) {
837+
const new_script = document.createElement("script");
838+
for (const attr of [...script.attributes]) {
839+
new_script.setAttribute(attr.name, attr.value)
840+
}
841+
new_script.textContent = script.textContent;
842+
script.replaceWith(new_script);
843+
}
844+
}
845+
}
846+
833847
return true;
834848
},
835849

0 commit comments

Comments
 (0)