I\'m writing a Chrome extension, I need to get my extension\'s id in my code, so I don\'t need to change it manually every time. How can I do this?
In WebExtensions, you have two options:
chrome.runtime.id
chrome.i18n.getMessage("@@extension_id")
In Chrome and Opera, they will return the same value, but in Firefox there is a difference.
In Firefox, chrome.runtime.id
will return the so called "Extension ID", but chrome.i18n.getMessage("@@extension_id")
will return the "Internal UUID". The extension ID is the same for all users, but the internal UUID is created when the extension is installed and is unique per user.
Depending on the context, the extension ID will not be what you want. For example, Firefox uses the internal UUID to fill the origin
header, not the extension ID.
Example 1: Ghostery in Firefox 61
chrome.runtime.id --> "firefox@ghostery.com"
chrome.i18n.getMessage("@@extension_id") --> "e3225586-81a0-47c3-8612-d95fb0c2a609"
For fetch
requests from within the extension, Firefox will add the header
origin: moz-extension://e3225586-81a0-47c3-8612-d95fb0c2a609
Example 2: Ghostery in Chrome
chrome.runtime.id --> "mlomiejdfkolichcflejclcbmpeaniij"
chrome.i18n.getMessage("@@extension_id") --> "mlomiejdfkolichcflejclcbmpeaniij"
For fetch
requests from within the extension, Chrome will add the header
origin: chrome-extension://mlomiejdfkolichcflejclcbmpeaniij