summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhackademix2019-11-16 09:55:16 +0100
committerhackademix2019-11-16 10:08:48 +0100
commit10aee8015ea077f30ee5177e0835e50768a3d700 (patch)
treea439b57b2caf522aca43354fecb61c74ef52dfbe
parentae0fdc18e71b4929ef8292e2fd30b27ce2a95021 (diff)
downloadnoscript-10aee8015ea077f30ee5177e0835e50768a3d700.tar.gz
noscript-10aee8015ea077f30ee5177e0835e50768a3d700.tar.xz
noscript-10aee8015ea077f30ee5177e0835e50768a3d700.zip
Fixed external scripts included in HEAD of file:// pages failing (issue #115).
-rw-r--r--src/content/staticNS.js24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/content/staticNS.js b/src/content/staticNS.js
index 236abb4..28dd2eb 100644
--- a/src/content/staticNS.js
+++ b/src/content/staticNS.js
@@ -67,8 +67,22 @@
let originalState = document.readyState;
let blockedScripts = [];
+ let localPolicyKey, localPolicy;
+ if (UA.isMozilla && /^(?:ftp|file):/.test(url)) {
+
+ localPolicyKey = `ns.policy.${url}|${browser.runtime.getURL("")}`;
+ let localPolicy = sessionStorage.getItem(localPolicyKey);
+ sessionStorage.removeItem(localPolicyKey);
+ if (localPolicy) {
+ debug("Falling back to localPolicy", localPolicy);
+ try {
+ this.setup(JSON.parse(localPolicy));
+ return;
+ } catch(e) {
+ error(e, "Could not setup local policy", localPolicy);
+ }
+ }
- if (/^(?:ftp|file):/.test(url)) {
addEventListener("beforescriptexecute", e => {
// safety net for synchronous loads on Firefox
if (!this.canScript) {
@@ -86,8 +100,14 @@
debug("Fetched %o, readyState %s", policy, document.readyState); // DEV_ONLY
this.setup(policy);
if (this.canScript && blockedScripts.length && originalState === "loading") {
- log("Running suspended scripts which are permitted by %s policy.", url)
+ log("Running suspended scripts which are permitted by %s policy.", url);
// something went wrong, e.g. with session restore.
+ if (url.startsWith("file:") && !localPolicy) {
+ stop();
+ sessionStorage.setItem(localPolicyKey, JSON.stringify(policy));
+ location.reload(false);
+ return;
+ }
for (let s of blockedScripts) {
// reinsert the script:
// just s.cloneNode(true) doesn't work, the script wouldn't run,