检查Chrome扩展程序是否以解压模式安装
有没有办法检测我是运行从我的.crx文件安装的扩展,还是通过加载解压扩展...按钮加载扩展?
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?
我知道这种情况下的ID差异,但我不想依赖代码中的硬编码字符串。
I'm aware about ID differences in that case, but I don't want to rely on hardcoded strings in the code.
如果从从我的 .crx
文件中安装,则意味着从Chrome Web Store安装,您可以简单地检查扩展清单。 json
获取 update_url
属性的值。 CWS在你上传你的扩展时添加它。
If by "installed from my .crx
file" you mean installed from Chrome Web Store you can simply check extension manifest.json
for value of update_url
attribute. CWS adds it when you upload your extension.
如果你有一个自托管的 .crx
文件,扩展信息使用 chrome.management.getSelf()
并检查返回的 installType rel =noreferrer> ExtensionInfo 对象。如果它表示development
,这意味着扩展程序在开发者模式下被解压缩。 normal
表示它是从 .crx
文件安装的。
If you have a self-hosted .crx
file, get your extension information using chrome.management.getSelf()
and check installType
of returned ExtensionInfo object. If it says "development"
that means that extension was loaded unpacked in developer mode. "normal"
means that it was installed from .crx
file.