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

400 views Asked by At

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 !

2

There are 2 answers

0
Jonathan DEKHTIAR On BEST ANSWER

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:

  • admin: The extension was installed because of an administrative policy
  • development: The extension was loaded unpacked in developer mode
  • normal: The extension was installed normally via a .crx file
  • sideload: The extension was installed by other software on the machine
  • other: The extension was installed by other means Enum "admin", "development", "normal", "sideload", or "other"

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";
    }
});
1
Luka Čelebić On

Most google chrome extensions on the store have a permanent extension ID. If you packaged you extension so that it uses the same extension ID with each update then you can simply hardcode that ID and check it inside that first if.

I recommend reading more about packaging chrome extensions here.

Specifically this part.