Skip to content

Commit b56ffac

Browse files
committed
Reduce synchronous policy retrieval impact on file: and ftp: document loading performance.
1 parent da5a90b commit b56ffac

File tree

2 files changed

+4
-137
lines changed

2 files changed

+4
-137
lines changed

src/content/syncFetchPolicy.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,14 @@
6666
return;
6767
}
6868

69-
debug("Initial readyState and body", document.readyState, document.body);
69+
debug("Initial document state", document.readyState, document.documentElement, document.head, document.body); // DEV_ONLY
7070

71-
let mustFreeze = UA.isMozilla
71+
let mustFreeze = document.head && UA.isMozilla
7272
&& (!/^(?:image|video|audio)/.test(document.contentType) || document instanceof XMLDocument)
7373
&& document.readyState !== "complete";
7474

7575
if (mustFreeze) {
7676
// Mozilla has already parsed the <head> element, we must take extra steps...
77-
7877
try {
7978
DocumentFreezer.freeze();
8079

@@ -85,7 +84,7 @@
8584
debug("Readystate: %s, suppressedScripts = %s, canScript = %s", readyState, DocumentFreezer.suppressedScripts, ns.canScript);
8685

8786
if (!ns.canScript) {
88-
setTimeout(() => DocumentFreezer.unfreeze(), 0);
87+
queueMicrotask(() => DocumentFreezer.unfreeze());
8988
let normalizeDir = e => {
9089
// Chromium does this automatically. We need it to understand we're a directory earlier and allow browser UI scripts.
9190
if (document.baseURI === document.URL + "/") {
@@ -156,7 +155,7 @@
156155
DocumentFreezer.unfreeze();
157156
let scripts = [], deferred = [];
158157
// push deferred scripts, if any, to the end
159-
for (let s of [...document.querySelectorAll("script")]) {
158+
for (let s of document.getElementsByTagName("script")) {
160159
(s.defer && !s.text ? deferred : scripts).push(s);
161160
s.addEventListener("beforescriptexecute", e => {
162161
console.debug("Suppressing", script);

src/lib/DocumentFreezer.js

Lines changed: 0 additions & 132 deletions
This file was deleted.

0 commit comments

Comments
 (0)