What I’m doing right now is:
When <browser src="..." /> loads, I attach data into its .contentWindow:
frame.addEventListener("load",function(){
this.contentWindow.someMethod = function(){};
},true);
Now I want to know if there is a way to do this earlier, into the <browser>‘s window prototype, or any Window prototype, as for example I can do in the “current” window:
// [W]indow is the constructor
Window.prototype.test = function(){ alert("hello"); };
// [w]indow is the instance
window.test();
There are currently two ways to inject properties into a window before any JavaScript code runs. Usually,
content-document-global-creatednotification is simpler. The other is implementingnsIDOMGlobalPropertyInitializerinterface. Both allow you to get notified when a new window loads and before that window runs JavaScript code.Here is the approximate code for doing it with the observer notification: