mardi 12 septembre 2017

inject javascript to iframe before rendering

I'm using prototype of "appendChild" to intercept all the calls to "appendChild" and i would like to inject my javascript to the "" of the iframe, but when i do i get an error because when i try to inject my code the iframe is still not ready so i'm getting an empty iframe with null in the contentDocument.

my code:

window.callbackFunc = function(elem, args) {

    for (var key in elem) {

        if(elem.hasOwnProperty(key) && elem[key].id && elem[key].id.includes('testframe'))
        {
            console.log("start");
            console.log(elem);


        }

    }


}
window.f = Element.prototype.appendChild;

Element.prototype.appendChild = function() {
    window.callbackFunc.call(this, arguments);
    return window.f.apply(this, arguments);
};

the output in the console is the iframe object but empty.

can i add my javascript to the head of the iframe before its ready? in the exact point where i print it in my code?




Aucun commentaire:

Enregistrer un commentaire