From b6ddc2d502882da49800f55743c842242a62b6e2 Mon Sep 17 00:00:00 2001 From: hackademix Date: Sun, 3 Nov 2019 13:32:07 +0100 Subject: Use fragments to reinsert and run previously blocked scripts. --- src/content/staticNS.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/content/staticNS.js b/src/content/staticNS.js index 82ef302..236abb4 100644 --- a/src/content/staticNS.js +++ b/src/content/staticNS.js @@ -86,11 +86,17 @@ debug("Fetched %o, readyState %s", policy, document.readyState); // DEV_ONLY this.setup(policy); if (this.canScript && blockedScripts.length && originalState === "loading") { - log("Blocked some scripts on %s even though they are actually permitted by policy.", url) + log("Running suspended scripts which are permitted by %s policy.", url) // something went wrong, e.g. with session restore. for (let s of blockedScripts) { - // reinsert the script - s.replaceWith(s.cloneNode(true)); + // reinsert the script: + // just s.cloneNode(true) doesn't work, the script wouldn't run, + // let's clone it the hard way... + try { + s.replaceWith(document.createRange().createContextualFragment(s.outerHTML)); + } catch (e) { + error(e); + } } } } -- cgit v1.2.3