Firefox 附加组件 ID 约定

Firefox Add-On ID Conventions

我正在使用 WebExtension API 编写 Firefox 附加组件。某些 API(例如 browser.storage.sync) require an 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.

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

等等

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

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

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

对于@格式,一般用[some ID/name for extension]@[something representing the developer]。虽然 @ 之前和之后的部分的格式看起来像是 username@domain,但我已经看到 "username" 为空白的附加 ID and/or "domain" 是一个单词。例如,@a 将是一个有效的 ID。

ID 必须是唯一的

除了格式要求外,还有一个要求:

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

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