Firefox website extension. Automatically updates an extension that is not on the list.

I have a Firefox extension ported with chrome. This is an extension for a particular site, and I host it on my web server to avoid a long browsing time on the developer's site.

Users install the extension via a button on my web page. Let's say the current version of the extension is 3. The button click handler looks like this:

document.getElementById('install_ext').addEventListener('click', function (e) { window.location.href = '/public/ffext_3.xpi'; }); 

When there is a new version of the built-in extension, say version 4, I delete the existing ffext_3.xpi file by adding the new ffext_4.xpi file to the shared folder and changing the href in js to '/ public / ffext_4. xpi "on the server. There is some user interface level processing, for example, the show install button if there is no extension, show the update button if an update is available, etc.

Everything works up to this point. But there are some mechanical things.

  • I need to manually modify the href file in the js file.

  • The user must update the extension manually when the user interface requests.

I tried using the InstallTrigger object, but I also had to specify the full xpi url, which has a version number.

 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'm not sure if I should update this url whenever I download a new extension. I try to avoid viewing delays, and therefore, I would not want to use the InstallTrigger method, unless this is the only way to automatically update the extension in users browsers.

Is there a way to update the extension automatically without user intervention? I think that if automatic updating is possible, I can avoid changing the xpi file names and make it href like '/public/ffext.xpi'. Am I right, or do I need to constantly update URLs even with an automatic in-place update mechanism?

+5
source share
1 answer

The MDN Updates page covers configuring automatic updates for the add-in. For add-ins hosted on AMO , this is handled without the need for development by a developer add-in.

You must have a URL that can serve your users in a formatted JSON update format.

WebExtensions:
For WebExtensions, you need to set the update_url key in your .json manifest at the URL of the update manifest. As an example (on 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. [There are no instal.rdf files in WebExtensions, and there are no manifest.json files in other types of add-ons. 1 ]. Such an instal.rdf entry will look (added to <Description about="urn:mozilla:install-manifest"> ):

 <em:updateURL>https://example.com/updates.json</em:updateURL> 

Update manifest

An example of an update manifest may look (as with all code from the above MDN update page):

 { "addons": { " addon@example.com ": { "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" } } } ] } } } 

  • You can use WebExtension inside the Add-on SDK extension or Bootstrap / Restartless ( Embedded WebExtensions ). If you do this on the Add-on SDK add-on, you can have all the files used to describe the Firefox add-ons. Package package.json (Add-on SDK) and manifest.json (WebExtension) before adding the Add-on SDK extension. After packaging (e.g. jpm xpi ) it will have install.rdf and may have chrome.manifest (both are used for all other types of Firefox add-ons).
+7
source

Source: https://habr.com/ru/post/1259576/


All Articles