2012-10-11 182 views

回答

17

如果通过“从我的.crx文件安装”您的意思是从Chrome网上应用店安装,您可以简单地检查manifest.json的属性值。 CWS在您上传扩展时添加它。

如果你有一个自托管.crx文件,使用chrome.management.getSelf()让您的扩展信息,并检查返回ExtensionInfo对象installType。如果它说"development"这意味着扩展程序在开发人员模式下解压缩加载。 "normal"表示它是从.crx文件安装的。

+3

Chrome已经推出了'chrome.management.getSelf',它更适合于这个目的。 – Xan

18

下面是一个代码示例如何做到这一点:

function isDevMode() { 
    return !('update_url' in chrome.runtime.getManifest()); 
} 

用于Kuoll Remote Web Debugger

+2

更简单的方法是使用[chrome.runtime.getManifest()](https://developer.chrome.com/extensions/runtime#method-getManifest)。 –

+0

哦,当然。固定。 –

1

如果扩展开发人员模式运行(即包装)通过检查是否含有update_url您可以检查属性在它的清单中。这取决于您的未打包的分机的清单而不是包含update_urlThe attribute will be automatically added when publishing via the Chrome Developer Dashboard

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');