Fixed regression: events suppressed on file:// pages unless scripts are allowed.
This commit is contained in:
parent
721ab768d1
commit
c1f0ef098f
|
@ -98,21 +98,37 @@
|
||||||
// Mozilla has already parsed the <head> element, we must take extra steps...
|
// Mozilla has already parsed the <head> element, we must take extra steps...
|
||||||
|
|
||||||
debug("Early parsing: preemptively suppressing events and script execution.");
|
debug("Early parsing: preemptively suppressing events and script execution.");
|
||||||
|
|
||||||
{
|
{
|
||||||
let eventTypes = [];
|
let eventTypes = [];
|
||||||
for (let p in document.documentElement) if (p.startsWith("on")) eventTypes.push(p.substring(2));
|
for (let p in document.documentElement) if (p.startsWith("on")) eventTypes.push(p.substring(2));
|
||||||
let eventSuppressor = e => {
|
let eventSuppressor = e => {
|
||||||
if (!ns.canScript) {
|
if (!ns.canScript) {
|
||||||
e.preventDefault();
|
|
||||||
e.stopImmediatePropagation();
|
e.stopImmediatePropagation();
|
||||||
e.stopPropagation();
|
debug(`Suppressing ${e.type} on `, e.target); // DEV_ONLY
|
||||||
if (e.type === "load") debug(`Suppressing ${e.type} on `, e.target);
|
|
||||||
} else {
|
|
||||||
debug("Stopping suppression");
|
|
||||||
for (let et of eventTypes) document.removeEventListener(et, eventSuppressor, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
debug("Starting event suppression");
|
||||||
for (let et of eventTypes) document.addEventListener(et, eventSuppressor, true);
|
for (let et of eventTypes) document.addEventListener(et, eventSuppressor, true);
|
||||||
|
|
||||||
|
ns.on("capabilities", () => {
|
||||||
|
if (!ns.canScript) {
|
||||||
|
try {
|
||||||
|
for (node of document.querySelectorAll("*")) {
|
||||||
|
let evAttrs = [...node.attributes].filter(a => a.name.toLowerCase().startsWith("on"));
|
||||||
|
for (let a of evAttrs) {
|
||||||
|
debug("Reparsing event attribute after CSP", a, node);
|
||||||
|
node.removeAttributeNode(a);
|
||||||
|
node.setAttributeNodeNS(a);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
error(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
debug("Stopping event suppression");
|
||||||
|
for (let et of eventTypes) document.removeEventListener(et, eventSuppressor, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventListener("beforescriptexecute", e => {
|
addEventListener("beforescriptexecute", e => {
|
||||||
|
@ -125,7 +141,8 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let replacement = document.createRange().createContextualFragment(s.outerHTML);
|
let replacement = document.createRange().createContextualFragment(s.outerHTML);
|
||||||
replacement._original = e.target;
|
replacement._original = s;
|
||||||
|
s._replaced = true;
|
||||||
earlyScripts.push(replacement);
|
earlyScripts.push(replacement);
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
dequeueEarlyScripts(true);
|
dequeueEarlyScripts(true);
|
||||||
|
|
Loading…
Reference in New Issue