Check if Chrome extension installed in unpacked mode
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.
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');
Here is a code sample how to do this:
function isDevMode() {
return !('update_url' in chrome.runtime.getManifest());
}