summaryrefslogtreecommitdiff
path: root/src/content
diff options
context:
space:
mode:
authorhackademix2019-10-23 17:12:01 +0200
committerhackademix2019-10-25 23:19:48 +0100
commit51e115d3bcd2ad683f264e7d9c97347e0afac14e (patch)
tree4231163cdaca8ac54e7a0106d2fb54598ab4a1b8 /src/content
parent7f4c3450fdc6895bf36eeba9c3184a0814275a21 (diff)
downloadnoscript-51e115d3bcd2ad683f264e7d9c97347e0afac14e.tar.gz
noscript-51e115d3bcd2ad683f264e7d9c97347e0afac14e.tar.xz
noscript-51e115d3bcd2ad683f264e7d9c97347e0afac14e.zip
Cleaner and tighter usage of SyncMessage to fetch policies.
Diffstat (limited to 'src/content')
-rw-r--r--src/content/staticNS.js44
1 files changed, 18 insertions, 26 deletions
diff --git a/src/content/staticNS.js b/src/content/staticNS.js
index a175220..40e2420 100644
--- a/src/content/staticNS.js
+++ b/src/content/staticNS.js
@@ -3,22 +3,6 @@
let listenersMap = new Map();
let backlog = new Set();
- let stopAndReload = beforeReloading => {
- debug("Should I reload? %o, now: %s", performance.now())
- if (location.href === "about:blank" || performance.now() > 10000 ) {
- debug("Won't reload.");
- return;
- }
- stop();
- setTimeout(() => {
- debug("Reloading...");
- if (typeof beforeReloading === "function") {
- beforeReloading();
- }
- location.reload();
- }, 1000)
- };
-
let ns = {
debug: true, // DEV_ONLY
get embeddingDocument() {
@@ -53,17 +37,25 @@
debug(`Fetching policy from document %s, readyState %s, content %s`,
document.URL, document.readyState, document.documentElement.outerHTML);
let url = document.URL;
- let isFileUrl = url.startsWith("file:");
- if (isFileUrl) {
- addEventListener("beforescriptexecute", e => {
- if (!this.canScript) e.preventDefault();
- }, true);
- }
-
- let policy = browser.runtime.sendSyncMessage(
- {id: "fetchPolicy", url, contextUrl: url});
+ addEventListener("beforescriptexecute", e => {
+ // safety net for syncrhonous load on Firefox
+ if (!this.canScript) e.preventDefault();
+ }, true);
- debug("Fetched %o, readyState %s", policy, document.readyState);
+ let policy = null;
+ for (;;) {
+ try {
+ policy = browser.runtime.sendSyncMessage(
+ {id: "fetchPolicy", url, contextUrl: url});
+ break;
+ } catch (e) {
+ if (e.message !== "Could not esablish connection. Receiving end does not exist.") {
+ break;
+ }
+ error("Background page ready yet, retrying to fetch policy...")
+ }
+ }
+ debug("Fetched %o, readyState %s", policy, document.readyState); // DEV_ONLY
this.setup(policy);
return true;