当前位置: 动力学知识库 > 问答 > 编程问答 >

Check if Chrome extension installed in unpacked mode

问题描述:

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?

I'm aware about ID differences in that case, but I don't want to rely on hardcoded strings in the code.

网友答案:

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.

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.

网友答案:

Here is a code sample how to do this:

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

Used in Kuoll Remote Web Debugger

分享给朋友:
您可能感兴趣的文章:
随机阅读: