Search code examples
firefoxfirefox-addonfirefox-addon-sdk

Firefox addon SDK, open an url automatically after Firefox startup?


With Firefox addon SDK, how to open specific url automatically after Firefox startup (for the purpose of testing page)

I've tried tabs.open(url) in this doc:

var tabs = require("sdk/tabs");
tabs.open("http://www.example.com");

And this one and a lot of Stackoverflow page ..., but none of them works at all...(It is still just a blank tab after $ cfx run)


Solution

  • I think you want to do this:

    const tabs = require('sdk/tabs');
    
    exports.main = function (options, callbacks) {
      if (options.loadReason === 'startup') {
        tabs.open('https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload');
      }
    };
    

    The documentation for this is located here:

    https://developer.mozilla.org/en-US/Add-ons/SDK/Tutorials/Listening_for_load_and_unload