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});
}, true);
ns.on("capabilities", () => {
seen.record({
request: {

View File

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