Michael Cole
Michael Cole

Reputation: 16217

How to check if my website's Firefox extension is installed in 2015

There are a bunch of older questions and answers I've tried. I'm clearly missing it.

I have a (restartless?) FF extension with a startup function:

var domains = [ "awesomesite.awesome" ];

var addon_domains = []; // list of domains the addon added
var PREF = "media.getusermedia.screensharing.allowed_domains";

function startup(data, reason) {
    if (reason === APP_STARTUP) {
        return;
    }
    var prefs = Components.classes["@mozilla.org/preferences-service;1"]
            .getService(Components.interfaces.nsIPrefBranch);
    var values = prefs.getCharPref(PREF).split(',');
    domains.forEach(function (domain) {
        if (values.indexOf(domain) === -1) {
            values.push(domain);
            addon_domains.push(domain);
        }
    });
    prefs.setCharPref(PREF, values.join(','));


   // Communicate extension has started when user browses to webpage via window object?
   // ?!?!?!?!
}

You can see the full code here.

This just needs to work for Firefox in the last year or so.

Any suggestions? These did not work.

Thanks!

Update

Here's the extension code I ended up using:

function startup(data, reason) {
    if (reason === APP_STARTUP) {
        return;
    }
    var prefs = Components.classes["@mozilla.org/preferences-service;1"]
            .getService(Components.interfaces.nsIPrefBranch);
    var values = prefs.getCharPref(PREF).split(',');
    domains.forEach(function (domain) {
        if (values.indexOf(domain) === -1) {
            values.push(domain);
            addon_domains.push(domain);
        }
    });
    prefs.setCharPref(PREF, values.join(','));

    // Set the cookies
    var ios = Components.classes["@mozilla.org/network/io-service;1"].getService(Components.interfaces.nsIIOService);
    var cookieSvc = Components.classes["@mozilla.org/cookieService;1"].getService(Components.interfaces.nsICookieService);

    domains.forEach(function (domain) {
      var cookieUri = ios.newURI("http://" + domain + "/", null, null);
      cookieSvc.setCookieString(cookieUri, null, "firefoxScreenSharing=ready;", null);
    });
}

And on the web page:

Helpers.pluginFirefox = function() {
  if (!bowser || bowser.name !== 'Firefox') return false;
  // Read the cookie
  return (document.cookie.indexOf('firefoxScreenSharing=ready') !== -1);
};

If you only have one domain, the domains.foreach() is superfluous.

Upvotes: 1

Views: 56

Answers (1)

Noitidart
Noitidart

Reputation: 37238

You cant do much from your website side. What I would recommend is, from your addon, create a cookie, with the domain/host being your website. Then from your website check if that cookie exists. If it exists, then its installed. :)

Of course on uninstall/disable of your addon you should delete that cookie.

Upvotes: 1

Related Questions