From 08a41b3a62c8621904e79ed4edf2039fffb45a64 Mon Sep 17 00:00:00 2001 From: hackademix Date: Thu, 31 Oct 2019 23:52:54 +0100 Subject: Fixed bug in policy fetching. --- src/content/staticNS.js | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/content') diff --git a/src/content/staticNS.js b/src/content/staticNS.js index 8f447e7..1d00ecf 100644 --- a/src/content/staticNS.js +++ b/src/content/staticNS.js @@ -35,14 +35,27 @@ fetchPolicy() { let url = document.URL; - if (url.startsWith("http")) { + debug(`Fetching policy from document %s, readyState %s, content %s`, + url, document.readyState, document.documentElement.outerHTML); + + if (!/^(?:file|ftp|https?):/i.test(url)) { (async () => { - this.setup(await Messages.send("fetchChildPolicy", {url, contextUrl: url})); + let policy; + try { + policy = await Messages.send("fetchChildPolicy", {url, contextUrl: url}); + } catch (e) { + console.error("Error while fetching policy", e); + } + if (policy === undefined) { + log("Policy was undefined, retrying in 1/2 sec..."); + setTimeout(() => this.fetchPolicy(), 500); + return; + } + this.setup(policy); })(); return; } - debug(`Fetching policy from document %s, readyState %s, content %s`, - url, document.readyState, document.documentElement.outerHTML); + let originalState = document.readyState; let blockedScripts = []; -- cgit v1.2.3