I have a firefox web extension ported from chrome. This is a site specific extension and I am hosting this on my web server to avoid lengthy review times on developer hub.
Users install extension through a button click on my web page. Let's say the current version of extension is 3. The button click handler is like this
document.getElementById('install_ext').addEventListener('click', function (e) {
window.location.href = '/public/ffext_3.xpi';
});
When there is a new version of extension built, say version 4, I am deleting the existing ffext_3.xpi file, adding the new ffext_4.xpi file in public folder and modifying the href in js to '/public/ffext_4.xpi' on the server. There is some UI level handling also like show install button if extension not present, show update button if update is available, etc
Everything is working till this point. But there are some mechanical things being done.
I have to modify the href in js file manually.
The user has to update the extension manually whenever the UI prompts.
I tried to use InstallTrigger object but there also, I had to give complete xpi url that has version number in it.
document.getElementById('install_ext').addEventListener('click', function (e) {
var params = {
"MyExtension": {URL: 'https://addons.mozilla.org/firefox/downloads/file/12345/myext-0.1.2-fx.xpi',
IconURL: '/public/exticon.png',
Hash: 'sha1:1234567890abcdefghij1234567890abcdefghij',
toString: function () {
return this.URL;
}
}
};
InstallTrigger.install(params);
});
I am not sure if I have to update this URL whenever I upload a new extension. I am trying to avoid review delays and so, I would not want to use InstallTrigger way unless it is the only way for automatic updating of extension on users' browsers.
Is there a way to update the extension automatically without user intervention? I am thinking that if automatic update is possible, I can avoid changing the file names of xpi and make that href as '/public/ffext.xpi'. Am I right or do I need to keep updating the urls even with automatic update mechanism in place?
MDN's Updates page covers setting up automatic updates for an add-on. For add-ons hosted on AMO, this is handled without the need for the add-on developer to do anything.
You need to have a URL which can serve to your users a JSON formatted update manifest.
WebExtensions:
For WebExtensions, you need to set an update_url
key in your manifest.json to the URL of the update manifest. As an example (from the above MDN page:
"applications": {
"gecko": {
"update_url": "https://example.com/updates.json"
}
}
All other types of add-ons:
For non-WebExtension add-ons, this URL is set in the instal.rdf file. [WebExtensions don't have instal.rdf files, and the other types of add-ons don't have manifest.json files.1] Such an instal.rdf entry would look like (added to the <Description about="urn:mozilla:install-manifest">
element):
<em:updateURL>https://example.com/updates.json</em:updateURL>
An example update manifest could look like (as with all the code, from the above MDN Updates page):
{
"addons": {
"[email protected]": {
"updates": [
{ "version": "0.1",
"update_link": "https://example.com/addon-0.1.xpi" },
{ "version": "0.2",
"update_link": "http://example.com/addon-0.2.xpi",
"update_hash": "sha256:fe93c2156f05f20621df1723b0f39c8ab28cdbeec342efa95535d3abff932096" },
{ "version": "0.3",
"update_link": "https://example.com/addon-0.3.xpi",
"applications": {
"gecko": { "strict_min_version": "44" } } }
]
}
}
}
jpm xpi
), it would have an install.rdf and might have a chrome.manifest (both used for all other types of Firefox add-ons).If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With