Skip to content

Commit c197005

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 e56b6bd commit c197005

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
@@ -818,9 +818,23 @@ const inject = {
818818
elementbefore: "before",
819819
}[cfg.action];
820820

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

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

0 commit comments

Comments
 (0)