Firefox web extension Auto update unlisted-and-self-hosted extension
Asked Answered
W

1

7

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.

  1. I have to modify the href in js file manually.

  2. 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?

Wulfe answered 11/11, 2016 at 5:18 Comment(4)
What do you consider a lengthy review time? Normal review times are much shorter than they once were.Streptokinase
You should read UpdatesStreptokinase
@makyen, could you post it as answer so that I can accept it? applications.gecko.update_url - this will do. I was not able to find this link on google so asked on SO. Thanks.Wulfe
I did post an answer, about 20 minutes ago (I had to take some time to flesh it out to more than a link-only answer). Is my answer not showing up for you? It's there when I refresh the page. You may be looking at an old version of the page.Streptokinase
S
10

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>

Update manifest

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" } } }
      ]
    }
  }
}

  1. You can use a WebExtension inside either a Add-on SDK extension or a Bootstrap/Restartless add-on (Embedded WebExtensions). If you do so inside an Add-on SDK based add-on, you might have all of the files used to describe Firefox add-ons. A package.json (Add-on SDK) and manifest.json (WebExtension) prior to the Add-on SDK extension being packaged. After packaging (e.g. jpm xpi), it would have an install.rdf and might have a chrome.manifest (both used for all other types of Firefox add-ons).
Streptokinase answered 11/11, 2016 at 6:22 Comment(3)
Is there an optiont for self-hosted extensions to update through http, as it was possible for SDK-based addons ( by signing the update manifest ). Can we use old style update.rdf for we extensions?Uncharitable
@Uncharitable - I'm not really sure what your question is. Are you asking if the update.rdf file can be served over HTTP instead of HTTPS for a WebExtension based add-on? If so, the answer is no. The URL for the update.rdf file must be HTTPS. The documentation for the applications key is explicit on this point. If your question is just basically "can updates for WebExtensions be self-hosted by providing a update.rdf?" Then the answer is yes.Streptokinase
Since my question isn't exactly the topic of this post, would you be so kind to take a look at https://mcmap.net/q/1481149/-updating-self-hosted-extensions-through-http/1183602 . I belive you have already answered it with your comment.Uncharitable

© 2022 - 2024 — McMap. All rights reserved.