Reputation: 510
I want to be able to ask users if they want to install my firefox extension when they sign in into my web app, in case they not already have installed it, or if their version is not the latest one. Is there a possibility to do this?
I was not able to gather helpfull information on this matter by searching the web. My current attempt looks like this:
$(function() {
if ("InstallTrigger" in window) {
var params = {
"Example": {
URL: "https://www.example.com/plugins/firefox/latest/example.xpi",
IconURL: "https://www.example.com/favicon.ico",
Hash: "sha1:37441290FFDD33AB0280BECD79E1EF",
toString: function () { return this.URL; }
}
};
alert(InstallTrigger.compareVersion("Example", "0.8"));
InstallTrigger.install(params);
}
});
The installation using InstallTrigger.install() works. But the call to InstallTrigger.compareVersion() leads to the error "TypeError: InstallTrigger.compareVersion is not a function" in Firefox 38. The same is true for InstallTrigger.getVersion().
compareVersion() is documented here: http://www.applied-imagination.com/aidocs/xul/xultu/elemref/ref_InstallTrigger.html. But I have also found discussions that compareVersion() is not related to firefox extensions, so I am confused.
How is it possible to only call InstallTrigger.install() when the installed extension version is not the current?
Upvotes: 2
Views: 517
Reputation: 510
I have now found an appropriate solution. InstallTrigger.compareVersion() and InstallTrigger.getVersion() are seemingly not any more part of the InstallTrigger API, and there also seems to be no other way to directly retrieve information about installed firefox plugins inside a web page.
The trick is that the extension can provide this information itself by inserting it into the page by manipulating the DOM. Here an example using the firefox SDK, which adds a CSS class to the body.
var pageMod = require("sdk/page-mod");
var contentScriptValue =
'document.body.className += " ExampleComFirefoxExtensionInstalledClass";';
pageMod.PageMod({
include: "*www.example.com*",
contentScript: contentScriptValue
});
The page can then check for the inserted information.
$(function() {
window.setTimeout(function() {
if ("InstallTrigger" in window &&
!$('body').hasClass('ExampleComFirefoxExtensionInstalledClass'))) {
var params = {
"Example": {
URL: "https://www.example.com/plugins/firefox/latest/example.xpi",
IconURL: "https://www.example.com/favicon.ico",
Hash: "sha1:37441290FFDD33AB0280BECD79E1EF",
toString: function () { return this.URL; }
}
};
InstallTrigger.install(params);
}
}, 500);
});
The timeout is needed because the plugin manipulates the DOM after the page is fully loaded.
Accordingly, the plugin could also insert its version number into the web page in order to be able to directly install newer versions.
Upvotes: 1