Search code examples
firefox-addonfirefox-addon-sdk

Firefox Add-on - How to inject scripts to tabs that were open before installation?


How can we inject our scripts to tabs that existed before our add-on was installed?

We would like to inject our scripts to all open tabs once the user install our add-on and without refreshing the pages.

Any idea how this can be done?

At the moment, we inject scripts to new tabs that the user open after our add-on is installed this way:

pageMod.PageMod({
    include: "*",
    contentScriptFile: [self.data.url("js/jquery-1.8.1.min.js"), self.data.url("content.js")],
    onAttach: function (worker) {

        worker.port.on('settings', function () {
            log('settings: get');
            var settings = {
              user: storage.user
            };

            worker.port.emit("settings", settings);
        });   
    }
});

btw, we use firefox add-on sdk 1.12

Thanks


Solution

  • Just add the option

    attachTo: ["existing"]