Skip to content

Commit c1f0ef0

Browse files
committed
Fixed regression: events suppressed on file:// pages unless scripts are allowed.
1 parent 721ab76 commit c1f0ef0

File tree

1 file changed

+24
-7
lines changed

1 file changed

+24
-7
lines changed

src/content/staticNS.js

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -98,21 +98,37 @@
9898
// Mozilla has already parsed the <head> element, we must take extra steps...
9999

100100
debug("Early parsing: preemptively suppressing events and script execution.");
101+
101102
{
102103
let eventTypes = [];
103104
for (let p in document.documentElement) if (p.startsWith("on")) eventTypes.push(p.substring(2));
104105
let eventSuppressor = e => {
105106
if (!ns.canScript) {
106-
e.preventDefault();
107107
e.stopImmediatePropagation();
108-
e.stopPropagation();
109-
if (e.type === "load") debug(`Suppressing ${e.type} on `, e.target);
110-
} else {
111-
debug("Stopping suppression");
112-
for (let et of eventTypes) document.removeEventListener(et, eventSuppressor, true);
108+
debug(`Suppressing ${e.type} on `, e.target); // DEV_ONLY
113109
}
114110
}
111+
debug("Starting event suppression");
115112
for (let et of eventTypes) document.addEventListener(et, eventSuppressor, true);
113+
114+
ns.on("capabilities", () => {
115+
if (!ns.canScript) {
116+
try {
117+
for (node of document.querySelectorAll("*")) {
118+
let evAttrs = [...node.attributes].filter(a => a.name.toLowerCase().startsWith("on"));
119+
for (let a of evAttrs) {
120+
debug("Reparsing event attribute after CSP", a, node);
121+
node.removeAttributeNode(a);
122+
node.setAttributeNodeNS(a);
123+
}
124+
}
125+
} catch (e) {
126+
error(e);
127+
}
128+
}
129+
debug("Stopping event suppression");
130+
for (let et of eventTypes) document.removeEventListener(et, eventSuppressor, true);
131+
});
116132
}
117133

118134
addEventListener("beforescriptexecute", e => {
@@ -125,7 +141,8 @@
125141
return;
126142
}
127143
let replacement = document.createRange().createContextualFragment(s.outerHTML);
128-
replacement._original = e.target;
144+
replacement._original = s;
145+
s._replaced = true;
129146
earlyScripts.push(replacement);
130147
e.preventDefault();
131148
dequeueEarlyScripts(true);

0 commit comments

Comments
 (0)