More accurate NOSCRIPT element emulation.

This commit is contained in:
hackademix 2020-07-29 00:42:20 +02:00
parent 5d92d1b974
commit 35d82bd801
2 changed files with 19 additions and 8 deletions

View File

@ -102,6 +102,7 @@ window.addEventListener("securitypolicyviolation", e => {
Messages.send("violation", {url, type}); Messages.send("violation", {url, type});
}, true); }, true);
ns.on("capabilities", () => { ns.on("capabilities", () => {
seen.record({ seen.record({
request: { request: {

View File

@ -6,26 +6,36 @@ function onScriptDisabled() {
onScriptDisabled = () => {}; onScriptDisabled = () => {};
let refresh = false; let refresh = false;
for (let noscript of document.querySelectorAll("noscript")) { for (let noscript of document.querySelectorAll("noscript")) {
// force show NOSCRIPT elements content // force show NOSCRIPT elements content
let replacement = createHTMLElement("span"); let replacement = document.createRange().createContextualFragment(noscript.innerHTML);
replacement.innerHTML = noscript.innerHTML;
noscript.replaceWith(replacement);
// emulate meta-refresh // emulate meta-refresh
let meta = replacement.querySelector('meta[http-equiv="refresh"]'); for (let meta of replacement.querySelectorAll('meta[http-equiv="refresh"]')) {
if (meta) {
refresh = true; refresh = true;
document.head.appendChild(meta); 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) { if (refresh) {
let html = document.documentElement.outerHTML; let html = document.documentElement.outerHTML;
window.addEventListener("load", e => { let rewrite = () => {
if (!e.isTrusted) return;
let document = window.wrappedJSObject ? window.wrappedJSObject.document : window.document; let document = window.wrappedJSObject ? window.wrappedJSObject.document : window.document;
document.open(); document.open();
document.write(html); document.write(html);
document.close(); document.close();
}); };
if (document.readyState === "complete") {
rewrite();
} else {
window.addEventListener("load", e => {
if (e.isTrusted) rewrite();
});
}
} }
{ {
let eraser = { let eraser = {