More accurate NOSCRIPT element emulation.
This commit is contained in:
parent
5d92d1b974
commit
35d82bd801
|
@ -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: {
|
||||||
|
|
|
@ -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 = {
|
||||||
|
|
Loading…
Reference in New Issue