Skip to content

Commit 95f60d0

Browse files
committed
Avoid synchronous policy fetching if document is already complete (e.g. on extension updates).
1 parent b45b247 commit 95f60d0

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/content/staticNS.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ const FILE_OR_FTP = /^(?:file|ftp):$/.test(location.protocol);
103103
let policy = null;
104104
for (let attempts = 10; !(policy || this.policy) && attempts-- > 0;) {
105105
try {
106-
debug(`Retrieving policy asynchronously (${attempts} attempts left).`);
106+
debug(`Retrieving policy asynchronously for ${document.readyState} ${url} (${attempts} attempts left).`);
107107
policy = await Messages.send(msg.id, msg) || this.domPolicy;
108108
debug("Asynchronous policy", policy);
109109
} catch (e) {
@@ -112,14 +112,15 @@ const FILE_OR_FTP = /^(?:file|ftp):$/.test(location.protocol);
112112
}
113113
setup(policy);
114114
});
115+
const {readyState} = document;
115116

116-
if (!this.syncFetchPolicy && this.embeddingDocument) {
117+
if (readyState == "complete" || !this.syncFetchPolicy && this.embeddingDocument) {
117118
asyncFetch();
118119
return;
119120
}
120-
debug(`Synchronously fetching policy for ${url}.`);
121+
debug(`Synchronously fetching policy for ${readyState} ${url}.`);
121122
let policy = null;
122-
let attempts = document.readyState == "loading" ? 100 : 1;
123+
let attempts = readyState == "loading" ? 100 : 1;
123124
let refetch = () => {
124125
try {
125126
policy = browser.runtime.sendSyncMessage(msg) || this.domPolicy;

0 commit comments

Comments
 (0)