Check if Chrome extension installed in unpacked mode

前端 未结 3 1336
独厮守ぢ
独厮守ぢ 2020-12-08 10:23

Is there a way to detect whether I\'m running an extension that was installed from my .crx file or the extension was loaded as via \'Load unpacked extension...\' button?

3条回答
  •  甜味超标
    2020-12-08 10:59

    An extension is running in developer mode (i.e. unpacked), when it does not contain the update_url field in its manifest.

    This works because an unpacked extension's JSON manifest file should not contain the update_url field. This field is automatically added when publishing via the Chrome Developer Dashboard.

    For example, debug logs that only appear during development.

    const IS_DEV_MODE = !('update_url' in chrome.runtime.getManifest());
    
    function debugLog(str) {
      if (IS_DEV_MODE) console.log(str);
    }
    
    debugLog('This only appears in developer mode');
    

提交回复
热议问题