Firefox Extension: New Tab Extension

I need to do some action when a new tab opens in Firefox. I am using addon-sdk and I am completely new to developing Firefox extensions.

I downloaded several new tab extensions to the repository, unzip them and mostly use the following code from them:

var newtab = {
    init: function ()
    {
        gBrowser.addEventListener("NewTab", newtab.opentab, false);
    },

    opentab: function (aEvent)
    {
        // action here
    }
}

window.addEventListener( "load", newtab.init, false);

They subscribe to a window load event, after which they have gBrowser to subscribe to a new open tab event.

When I try to do this, I get:

Message: ReferenceError: window not defined

As I understand it, in this context there is no window object.

Firefox Addon-sdk. When loading page

stack overflow

sdk SO, , ( ), xul, .

SO answer Firefox Add-On window.addEventListener error: , Firefox .

? xul , ?

+4
2

-, , XUL SDK (, SDK, , ).

SDK API sdk/tabs. .

+4

:

var data = require('sdk/self').data;

require('sdk/page-mod').PageMod({
  include: ["about:newtab"],
  //contentScriptFile: [data.url('cs.js')], // <<< you dont need this unless you want to run stuff inside the about:newtab page
  attachTo: ["existing", "top"], // <<<< im not sure what this does
  onAttach: function(worker) {
    worker.port.emit('attached', true);
  }
});

self.port.on('attached', function() {
  console.log('new tab page loaded!!!');
});

: im sdk, , , ,

+3

Source: https://habr.com/ru/post/1546530/


All Articles