在我的 Firefox 扩展中实施分析?

发布于 2024-12-10 12:08:41 字数 151 浏览 0 评论 0原文

我想收集有关用户如何使用我的扩展程序的信息。我的想法是,每当用户与我的扩展程序交互时,我都会将信息(时间、收集的数据)写入配置文件文件夹中的本地文件。我会定期将该文件发送到服务器。

这是做我正在尝试的事情的正确方法吗?这会导致性能下降吗?

有更好的方法吗?

I want to collect information on how user uses my extension. What I am thinking is i am going to write the information(time,data collected) whenever user interacts with my extension to a local file within the profile folder. And I will send that file to the server periodically.

Is this is a correct way of doing what I am trying? Is this going to produce any performance degradation?

Is there any better way of doing this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

微暖i 2024-12-17 12:08:42

您必须考虑的事项:磁盘 I/O 可能会花费不可忽略的时间,例如,如果磁盘繁忙或用户的配置文件位于网络位置。因此,打开文件、向其中写入一行数据并再次关闭文件的明显方法确实会降低性能,因为在写入文件时浏览器 UI 会被阻止。您的选择是:

What you have to consider: disk I/O can take non-negligible amounts of time, e.g. if the disk is busy or if the user's profile is located on a network location. So the obvious approach to open a file, write a line of data into it and close the file again would indeed degrade performance because the browser UI is blocked while you are writing into the file. Your options are:

  • Open the file once and use nsIBufferedOutputStream with a sufficiently large buffer. This will have the effect that only few of your write operations will trigger a write to disk. Downsides: you still have synchronous write operations every now and then, and if the browser crashes the buffer contents will not be written out to disk - your file gets corrupted.
  • Use NetUtil.asyncCopy() to write data asynchronously, without blocking everything. The code example in the documentation shows how one would write a string using nsIStringInputStream. Downside: this is probably not terribly efficient memory-wise, a number of XPCOM objects needs to be created for each write operation.
  • Use an SQLite database, it gives you asynchronous API and ensures consistency even if the browser crashes. If you open the database connection only once and then write into it every now and then it should be more efficient than the solution above (but I didn't test). Downside: your result is a database file rather than a plain text file, you either have to convert it before sending to the server or the server needs to process an SQLite database (which might be more complicated than reading a text file).
浪推晚风 2024-12-17 12:08:42

我认为这种态度没有什么问题,绝对比臭名昭著的小块发送要好。

但是,您应该非常清楚地写出您想要发送该数据(并且可能在用户安装附加组件后显示一个包含一些信息的新选项卡),因为有些用户不太喜欢被监视。

您可以使用 XMLHttpRequest 发送数据(请参阅此处)。

I see nothing wrong with that attitude, definitely better than sending it notoriously in small chunks.

However you should write it very clearly that you want to send that data (and perhaps display a new tab with some information after user installs the add-on), because some users don't quite like to be spied.

You can send data with XMLHttpRequest (see here).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文