如何判断一个真正的用户和我在开发过程中是否安装了Chrome扩展? [英] How to tell if a Chrome extension is installed by a real user vs. by me during development?

查看:150
本文介绍了如何判断一个真正的用户和我在开发过程中是否安装了Chrome扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Chrome扩展程序中使用Google Analytics。只有当扩展名被一个真实的人使用时,我才想执行分析代码(而不是在我工作的时候)。以下任何一种都可行,哪种最好?


  1. 确定扩展是安装打包还是解压缩。我认为这是最好的,因为明确解包意味着它正在开发中,并且它不是特定于我的机器的。该扩展能够以编程方式了解这一点吗?


  2. 让扩展查找特定于我的环境的内容。我不确定这是什么东西(扩展名是开源的,所以它不能是任何私人的东西)。


  3. 有一个开发人员模式选项页面上的选项。可以,但这意味着任何安装扩展的人都可以打开它。 手动设置localStorage变量并永不删除它。可行但不是最好的解决方案,因为如果它消失了,我不得不重置它。我必须记住,如果我从localStorage删除密钥,不要删除它。


  4. var useAnalytics = false

  5. 你的产品扩展将有一个 extension_id ,它不会改变,而你的解压后的扩展将有一个随机的< / $ gt; code> extension_id ,如果您再次删除并加载它,它将会改变。您可以使用 il8n API 获取 extension_id 检查它是否与生产 extension_id



    var extensionId = chrome.i18n.getMessage('@@ extension_id');


    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?

    解决方案

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

    这篇关于如何判断一个真正的用户和我在开发过程中是否安装了Chrome扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆