Configurable capability to show noscript elements on script-disabled pages.

This commit is contained in:
hackademix 2021-02-14 19:57:27 +01:00
parent 12c654f130
commit c42cbb7290
5 changed files with 77 additions and 91 deletions

View File

@ -577,6 +577,9 @@
"cap_ping": { "cap_ping": {
"message": "ping" "message": "ping"
}, },
"cap_noscript": {
"message": "noscript"
},
"cap_other": { "cap_other": {
"message": "other" "message": "other"
}, },

View File

@ -238,7 +238,19 @@ var LifeCycle = (() => {
if (Ver.is(previousVersion, "<=", "11.0.10")) { if (Ver.is(previousVersion, "<=", "11.0.10")) {
log(`Upgrading from 11.0.10 or below (${previousVersion}): configure the "ping" capability.`); log(`Upgrading from 11.0.10 or below (${previousVersion}): configure the "ping" capability.`);
await ns.initializing; await ns.initializing;
ns.policy.TRUSTED.capabilities.add("ping") ns.policy.TRUSTED.capabilities.add("ping");
await ns.savePolicy();
}
if (Ver.is(previousVersion, "<", "11.2.rc4")) {
log(`Upgrading from ${previousVersion}: configure the "noscript" capability.`);
await ns.initializing;
let {DEFAULT, TRUSTED, UNTRUSTED} = ns.policy;
// let's add "noscript" to DEFAULY, TRUSTED and any CUSTOM preset
let presets = [DEFAULT, TRUSTED];
presets = presets.concat([...ns.policy.sites.values()].filter(p => p !== TRUSTED && p !== UNTRUSTED));
for (let p of presets) {
p.capabilities.add("noscript");
}
await ns.savePolicy(); await ns.savePolicy();
} }
}, },

View File

@ -1,51 +1,22 @@
// depends on /nscl/content/NoscriptElements.js
"use strict";
function onScriptDisabled() { function onScriptDisabled() {
if (document.readyState === "loading") {
if (!onScriptDisabled._installed) {
window.addEventListener("DOMContentLoaded", e => onScriptDisabled());
onScriptDisabled._installed = true;
}
return;
}
onScriptDisabled = () => {}; onScriptDisabled = () => {};
let refresh = false;
for (let noscript of document.querySelectorAll("noscript")) {
// force show NOSCRIPT elements content let emulateNoScriptElement = () => {
let replacement = createHTMLElement("span"); if (ns.allows("noscript")) {
replacement.innerHTML = noscript.innerHTML; NoscriptElements.emulate(true);
// emulate meta-refresh
for (let meta of replacement.querySelectorAll('meta[http-equiv="refresh"]')) {
refresh = true;
document.head.appendChild(meta);
console.log(`State %s, emulating`, document.readyState, meta);
}
if (noscript.closest("head") && document.body) {
document.body.insertBefore(noscript, document.body.firstChild);
}
noscript.replaceWith(replacement);
}
if (refresh) {
let html = document.documentElement.outerHTML;
let rewrite = () => {
let document = window.wrappedJSObject ? window.wrappedJSObject.document : window.document;
try {
document.open();
document.write(html);
document.close();
} catch (e) {
error(e);
} }
}; };
if (document.readyState === "complete") {
rewrite(); if (document.readyState === "loading") {
window.addEventListener("DOMContentLoaded", emulateNoScriptElement, true);
return;
} else { } else {
window.addEventListener("load", e => { emulateNoScriptElement();
if (e.isTrusted) rewrite();
});
} }
}
{
let eraser = { let eraser = {
tapped: null, tapped: null,
delKey: false, delKey: false,
@ -95,5 +66,4 @@ function onScriptDisabled() {
} }
eraser.tapped = null; eraser.tapped = null;
}, true); }, true);
}
} }

View File

@ -100,8 +100,9 @@
"lib/CSP.js", "lib/CSP.js",
"nscl/content/patchWindow.js", "nscl/content/patchWindow.js",
"common/CapsCSP.js", "common/CapsCSP.js",
"/nscl/common/RequestKey.js", "nscl/common/RequestKey.js",
"content/DocumentCSP.js", "content/DocumentCSP.js",
"nscl/content/NoscriptElements.js",
"content/onScriptDisabled.js", "content/onScriptDisabled.js",
"content/staticNS.js", "content/staticNS.js",
"content/PlaceHolder.js", "content/PlaceHolder.js",

@ -1 +1 @@
Subproject commit 077b98985354ca42b9a73fd49d3c8c5b8b42ddfe Subproject commit 48d590749688928dda8e27e7e1e4e388057f4836