Skip to content

Commit edcdeea

Browse files
committed
Fallback to syncrhonous policy fetching if the document is already loaded (e.g. on updates).
1 parent 0ff5320 commit edcdeea

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/content/staticNS.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,18 @@
8686
debug("Fetching policy for actual URL %s (was %s)", url, document.URL);
8787
}
8888

89-
debug(`Synchronously fetching policy for ${url}.`);
9089
if (this.syncFetchPolicy) {
9190
// extra hops to ensure that scripts don't run when CSP has not been set through HTTP headers
9291
this.syncFetchPolicy();
9392
} else {
94-
this.setup(
95-
browser.runtime.sendSyncMessage({id: "fetchPolicy", url, contextUrl: url})
96-
);
93+
let msg = {id: "fetchPolicy", url, contextUrl: url};
94+
if (document.readyState === "complete") {
95+
// no point fetching synchronously, since the document is already loaded (hot extension update?)
96+
(async () => this.setup(await browser.runtime.sendMessage(msg)))();
97+
} else {
98+
debug(`Synchronously fetching policy for ${url}.`);
99+
this.setup(browser.runtime.sendSyncMessage(msg));
100+
}
97101
}
98102
},
99103

0 commit comments

Comments
 (0)