I'm writing a userscript and need to make it so any iframe
appended to the DOM with document.body.appendChild()
's content document has the hidden
getter set to always return false.
I can change the getter with:
iframe.contentDocument.__defineGetter__("hidden",()=>false)
I need this to modify elements before they're added to the DOM, so that
var i = document.createElement("iframe");
i.sandbox = "allow-same-origin";
document.body.appendChild(i);
document.__defineGetter__("hidden", i.contentDocument.__lookupGetter__("hidden"))
will always redefine the document hidden
getter to return false.
I've tried:
const oldAppend = Node.prototype.appendChild;
Node.prototype.appendChild = function (child) {
child?.contentDocument?.__defineGetter__("hidden",()=>false);
return oldAppend(child);
}
But then when I try to use the appendChild
method, I get: TypeError: 'appendChild' called on an object that does not implement interface Node.
Is there a way (in pure JS) to change the appendChild
method so that it does this for every iframe
that gets appended to the DOM?
Node.prototype.appendChild
to do this.TypeError: 'appendChild' called on an object that does not implement interface Node.
when I tried that.