I'm using Analytics in my Chrome extension. I want to execute the analytics code only if the extension is being used by a real person (not me while I'm working on it). Are any of the following doable and which is the best?
Identify whether the extension was installed packed or unpacked. I think this is the best because unpacked clearly means it's "in development" and it's not specific to my machine in any way. Can the extension know this programatically?
Have the extension look for something that's specific to my environment. I'm not sure what that something is (extension is open-source so it can't be anything too private).
Have a "developer mode" option on the options page. Doable but that means anyone who installs the extension can just turn it on.
Set a localStorage variable manually and never erase it. Doable but not the best solution because if it ever disappears, I'd have to reset it. And I have to remember not to delete it if I ever delete keys from localStorage.
var useAnalytics = false
while developing, set it to true before releasing. It's not automatic but its an option.
Something else?
Let’s update the Chrome screen capture example to check for the extension. Open up chrome/index.html from the repo. First, hide the “Get the screen” button so that no-one tries to interact with it when we don’t know if it will work or not. When the page loads we are going to send the message "version" to the extension to see if it is present.
Open the Chrome Web Store page for each extension you wish to check. While on the Chrome Web Store page for an extension, click on the Chrome Extension Source Viewer “CRX” icon next to the URL bar. Click “View Source”. Wait for the new page to fully load, then find and open the “manifest.json” file.
When you install a Chrome extension, you’re essentially entering into a trust-based relationship with the creator of that extension. You’re allowing the extension to live in your browser, potentially watching everything you do. We’re not suggesting that they all do this—but the ability is there.
The extension is currently installed and enabled so the “Get the screen” button will appear the current extension version will be logged in the console. Disable the extension from the Chrome extensions settings (chrome://extensions) and reload the page. This time, the button will not appear and the console log will read “No extension”.
Your production extension will have a single extension_id
that will not change while your unpacked extension will have a random extension_id
that will change if you remove and load it again. You can use the il8n API to get the extension_id
check if it matches the production extension_id
.
var extensionId = chrome.i18n.getMessage('@@extension_id');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With