Search code examples
google-chrome-extension

How to know chrome extension is in development or production environment?


You often face situations where you have to set different variables for development and production environments. For example, if your extension has to access external API, you want to disable this when you are running your development version. So far, I've checked the chrome.runtime.id to see if it matches the published one's id.

Is there a better way than this?


Solution

  • Take a look at management.get, it will return information about the installed extension/app, and you can distinguish the environment by checking the installType of the returned info.

    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.