javascript - Firefox 附加组件 ID 约定

标签 javascript firefox firefox-addon firefox-addon-webextensions

我正在使用 WebExtension API 编写一个 Firefox 附加组件。一些 API(例如 browser.storage.sync)需要 Add-On ID在附加组件的 manifest.json 文件中明确声明。

documentation for IDs状态:

The ID of the extension, which must be one of the following:

  • GUID (Firefox 1.0)
  • A string formatted like so: extensionname@example.org

The latter format is significantly easier to generate and manipulate. Firefox 1.5 has checking to ensure that your id falls into one format or the other and will refuse to install add-ons that have malformed ids. You should not use a real email address for your id, however, as it might attract spam.

关于我可以提供什么样的字符串,文档不是很清楚。是不是……

  • 任何有效的电子邮件地址?
  • 任何“看起来像”something@something.something 的字符串?
  • a@b.c.d.e.f.g 怎么样?
  • 它应该与扩展本身相关吗?
  • 它应该有我拥有的域名还是可以是任何域名?

等等

因为我必须显式声明 ID 才能使用 browser.storage.sync,所以我无法依赖 automatic ID Firefox 可以为 WebExtensions 提供。

在 Firefox 中显式声明附加组件 ID 的约定是什么?

最佳答案

实际要求是ID matches the following RegExp :

var gIDTest = /^(\{[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\}|[a-z0-9-\._]*\@[a-z0-9-\._]+)$/i

使用 GUID 或类似于电子邮件地址的东西是一项要求,这在 MDN documentation on Install Manifests 中有明确规定。 (用于遗留附加组件)。从 Firefox 1.5 开始,通过在 Firefox 代码中放置的检查来确定它是其中之一。上面的RegExp可以描述为:

  1. 必须是 GUID使用 {8digits-4digits-4digits-4digits-12digits}
  2. 格式的十六进制数字
  3. 包含单个 @ 且在 @ 之后至少有 1 个字符的字符串。
    1. @ 格式中的所有字符都必须匹配 /[a-z0-9-\._]/i(除了单个 @).
    2. @ 格式在 @ 之前可以有零个或多个字符
    3. @ 格式不需要是有效的电子邮件地址。它不必具有有效域。它甚至不需要是一个有效的电子邮件地址。它只需要匹配 RegExp。

recommended that if you are selecting an ID, that you use the @ format, not a GUID .

对于@格式,一般用作[一些ID/name for extension]@[something representing the developer]。虽然 @ 前后的部分往往有一种格式,看起来像是 username@domain,但我已经看到附加 ID 的“用户名”为空和/或“域”是一个词。例如,@a 将是一个有效的 ID。

ID必须是唯一的

除了格式要求外,还有以下要求:

  • 该 ID 在已提交给 Mozilla 的所有附加组件中必须是唯一的(由任何人提交)。

至于它在提交给 Mozilla 的所有附加组件中是独一无二的:当您第一次尝试将它提交给 Mozilla 进行签名时,您会发现它是否是独一无二的。如果它已经存在,您必须更改它才能成功提交您的附加组件。

关于javascript - Firefox 附加组件 ID 约定,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45339492/

相关文章:

c# - 关闭 Firefox 后 ASP.NET 身份验证 cookie 不会删除

firefox - 自动启动 x-server 和自己的服务

javascript - FF 3.5 扩展名 : window. 标题为 'undefined'

javascript - 对 Firefox 扩展进行逆向工程

javascript - jQuery:从逗号分隔的字符串创建html元素?

javascript - onCanvasClick(event) 不适用于 visual studio ultimate

javascript - CSS 应该包含在 NPM 组件库中还是手动加载?

javascript - jQuery cookie : How can I save the color selection of the user for the next visit?

firefox - CSS3 -moz-mask 支持

firefox-addon - 使用相同的 XUL 覆盖时是否应该指定应用程序?