google-chrome-extensionfirefox-addon-webextensionsopera-extensionmicrosoft-edge-extension

How to know whether a chrome extension is downloaded from store?


I develop a chrome extension which is also compatible with Firefox/Edge/Opera.

The extension rely on a REST API accessible over the web. During the web development, I prefer pointing to a development endpoint where it does not affect the production tenant and only affect a development instance and database.

My question is then quite simple, I would like to make similar to this pseudo-code:

if (extension.downloaded_from_store == true)
    endpoint = "https://api-dev.example.com"
else
    // The extension has been installed from a local directory
    endpoint = "https://api-prod.example.com"

Do you have any idea how I could do such thing (preferably from the background.js page) ?

If the solution can be compatible with all browsers, it would be perfect !


Solution

  • I found the answer in the chrome documentation in the management module:

    Link: https://developer.chrome.com/extensions/management#type-ExtensionInstallType

    ExtensionInstallType

    How the extension was installed. One of:

    This allows me to do the following:

    chrome.management.get(chrome.runtime.id, function(app_info){
        if (app_info.installType == "development"){
            endpoint = "https://api-dev.example.com";
        }
        else {
            endpoint = "https://api-prod.example.com";
        }
    });