Search code examples
firefox-addonfirefox-addon-sdk

How to distinguish between dev and production in a Firefox extension I'm building?


In my Google Chrome extension, I'm using this nifty little trick to distinguish the dev version from the production version: How to tell if a Chrome extension is installed by a real user vs. by me during development?

Is there a similar trick I can use for a Firefox extension? I'd like to use some slightly different settings in my code while developing, but without having to manually change them before releasing.

Something like:

if (addon_in_development) {
    setting = 'abc';
}
else {
    setting = 'def';
}

Solution

  • You could set an environment variable in the shell, and detect it like this:

    var { env } = require('api-utils/environment');
    
    console.log(env.IS_DEV);
    console.log(typeof env.IS_DEV);
    
    if (env.IS_DEV) {
        console.log("IS_DEV is set, we're running under cfx run...");
    }
    else {
        console.log("IS_DEV is not set?");
    }
    

    See the docs for more info:

    https://addons.mozilla.org/en-US/developers/docs/sdk/1.7/packages/api-utils/environment.html

    Using the above use case, you would run cfx like this:

    IS_DEV=1 cfx run