问题
I'm writing a Firefox Add-On using the WebExtension API. Some of the APIs (such as browser.storage.sync) require an Add-On ID to be explicitly declared in the add-on's manifest.json
file.
The documentation for IDs states:
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.
The documentation is not very clear with regards to what kind of string I can provide. Is it...
- Any valid email address?
- Any string that "looks like" something@something.something?
- How about a@b.c.d.e.f.g?
- Should it be relevant to the extension itself?
- Should it have a domain name I own or can it be any?
etc.
Because I must declare the ID explicitly to use browser.storage.sync
, I am unable to depend on the automatic ID that can be provided by Firefox for WebExtensions.
What are the conventions for explicitly declared add-on IDs in Firefox?
回答1:
The actual requirement is that the 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
The use of a GUID or something approximating an email address is a requirement which is clearly stated in the MDN documentation on Install Manifests (used in legacy add-ons). That it is one or the other is enforced by a check which was placed in the Firefox code as of Firefox 1.5. The above RegExp can be described as:
- Must be a GUID using hexadecimal digits in the format
{8digits-4digits-4digits-4digits-12digits}
or - A string containing a single
@
with at least 1 character after the@
.- All characters in the
@
format must match/[a-z0-9-\._]/i
(other than the single@
). - The
@
format can have zero or more characters prior to the@
- The
@
format does not need to be a valid email address. It doesn't have to have a valid domain. It doesn't even need to be something which could be a valid email address. It just has to match the RegExp.
- All characters in the
It's recommended that if you are selecting an ID, that you use the @ format, not a GUID.
For the @
format, it's generally used as [some ID/name for extension]@[something representing the developer]
. While the part before and after the @
tend to have a format that looks like it could be username@domain, I've seen add-on IDs where the "username" is blank and/or the "domain" is a single word. For example, @a
would be a valid ID.
The ID must be unique
In addition to the format requirements, there is the requirement that:
- The ID must be unique across all add-ons that have been submitted to Mozilla (by anyone, ever).
As to it being unique among all add-ons submitted to Mozilla: You'll find out if it's unique when you first attempt to submit it to Mozilla for signing. If it does already exist, you will have to change it in order to successfully submit your add-on.
来源:https://stackoverflow.com/questions/45339492/firefox-add-on-id-conventions