I need to do some actions when new tab in Firefox is opened. I'm using addon-sdk and I'm totally new to firefox extensions development.
I downloaded some new tab extensions in store, unpack them and mostly of them use such code:
var newtab = {
init: function ()
{
gBrowser.addEventListener("NewTab", newtab.opentab, false);
},
opentab: function (aEvent)
{
// action here
}
}
window.addEventListener( "load", newtab.init, false);
They are subscribing on load event of window, then they guaranteed have gBrowser to subscribe on new tab opened event.
When I'm trying to do this, I'm getting:
Message: ReferenceError: window is not defined
As far as I understood, there is no window object in that context.
Firefox Addon-sdk. On page load
StackOverflow – Firefos Addon: eventlistener: windows is not defined
According to sdk and SO answer, It's possible to do it described way, the only difference between my extension and downloaded extensions from the store (and above topics), that I haven't any xul files, because I haven't any UI.
I also tried to use code from SO answer Firefox Add-On window.addEventListener error: window not defined, but the Firefox is crashing.
How to do it right way? Should I have any xul files if I have no UI?
Thar code you're quoting is regular XUL overlay code, and does not apply to the SDK (well, it could be made to work in the SDK by jumping through a lot of hoops, but that's beside the point).
The SDK provides APIs for dealing with tabs in the sdk/tabs
module. You should use that.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With