Are there any way I can set getters and setters of src attribute of all HTMLSourceElements? I'm thinking about using this as an extra security measures for my web app which uses JS from other websites. By "setters of src attribute of all HTMLSourceElements", I mean that the setter should be called on code like: SomeVideoElement.src = "/static/somevideo.mp4"
So far, I've tried:
HTMLElement.prototype.__defineGetter__("src", function () {
console.log("getter called!");
debugger;
});
HTMLElement.prototype.__defineSetter__("src", function (val) {
debugger;
});
//tested at chrome, didn't yield any logs (getters and setters not called)
and
HTMLSourceElement.prototype._setAttribute = HTMLSourceElement.prototype.setAttribute;
HTMLSourceElement.prototype._getAttribute = HTMLSourceElement.prototype.getAttribute;
HTMLSourceElement.prototype.setAttribute = function(){
console.log("HTMLSourceElement.setAttribute called!");
debugger;
HTMLSourceElement.prototype._setAttribute.apply(this, arguments);
}
//tested at chrome. Called only for codes like: SomeVidElem.setAttribute("src",someurl)
are there any way to do this? Or is this simply impossible? Thanks : )