Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell if a Chrome extension is installed by a real user vs. by me during development?

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?

  1. 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?

  2. 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).

  3. Have a "developer mode" option on the options page. Doable but that means anyone who installs the extension can just turn it on.

  4. 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.

  5. var useAnalytics = false while developing, set it to true before releasing. It's not automatic but its an option.

  6. Something else?

like image 874
Alex Grin Avatar asked Jan 27 '12 14:01

Alex Grin


People also ask

How do I check if a Chrome extension is available?

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.

How do I view the source code of a Chrome extension?

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.

Why should you install Chrome extensions?

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.

Why is the Chrome extension not showing up on my screen?

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”.


1 Answers

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

like image 84
abraham Avatar answered Nov 15 '22 10:11

abraham