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

孤街醉人 提交于 2019-12-19 07:49:50

问题


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?


回答1:


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




回答2:


You can install the Google Analytics opt-out https://chrome.google.com/webstore/detail/fllaojicojecljbmefodhfapmkghcbnh?hl=en



来源:https://stackoverflow.com/questions/9034702/how-to-tell-if-a-chrome-extension-is-installed-by-a-real-user-vs-by-me-during-d

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!