Click here to Skip to main content
Click here to Skip to main content

Detecting a Firefox Extension Using JavaScript

By , 29 Jul 2008
Rate this:
Please Sign up or sign in to vote.

Introduction

The article will be helpful for developers of Firefox extensions (add-ons). It describes how your web pages can detect if an extension is currently installed in your browser.

Background

The requirement is of a very typical distribution policy, where we deliver our extensions using the most popular pages of our website. Each of these popular pages, when visited, would detect if the extension if already installed; if so, it shouldn't make an attempt to download and install the extension again. However, if the extension is not installed, it can be downloaded and installed.

The code can further take care of settings cookies, and doing it periodically (once in a week), in case a user denies to install the extension - for whatever reason.

Using the code

I was stuck with detecting the existence of an extension (add-on) in Firefox using JavaScript. I used the following code to detect the presence of an extension:

<img src="chrome://toolbar/content/logo.png" 
 onload="var a=document.getElementById('PlugInStatus'); 
    a.innerHTML = 'You are using the plug-in';" 
    style="visibility: hidden;" />

<span id="PlugInStatus">You are not using the plug-in</span><noscript> 
      and/or you don't have JavaScript turned on</noscript>

The problems started arising with the launch of Firefox 3 RC1. The above code always failed from the HTMLs I needed to detect the plug-in. Browsing through Mozilla Dev docs, I came across the following: http://developer.mozilla.org/en/docs/Chrome_Registration#contentaccessible. However, there wasn't much available telling me what file(s) exactly I should modify.

Well, here is the answer for those who are stuck with something similar:

  1. Locate your chrome.menifest at the plug-in installation location, typically located at:
  2. C:\Documents and Settings\sauda\ApplicationData\Mozilla\Firefox\
       Profiles\j3nyyp9a.Saud\extensions\{33CC0A72-4C68-4D38-A06D-D51BA6A8A53E} 
  3. Open chrome.menifest and edit the contents as shown below:
  4. Existing code:

    content toolbar jar:chrome/toolbar.jar!/content/toolbar/ 

    Updated code:

    content toolbar jar:chrome/toolbar.jar!/content/toolbar/ 
    content toolbar jar:chrome/toolbar.jar!/content/toolbar/ contentaccessible=yes 

Both the lines are important as the first one makes it work in Firefox 2.0, since this version of Firefox doesn't understand the contentaccessible keyword. And, the second one is required for Firefox 3.0.

Kill any current instances of Firefox before you test your HTMLs/JSs.

Points of Interest

An interesting argument about the same can be found at Mozilla's Bugzilla system: https://bugzilla.mozilla.org/show_bug.cgi?id=292789.

Another interesting read with reference to "Chrome" is available at: http://cybernetnews.com/2008/06/24/myfive-firefox-3-chrome-urls/.

History

  • Draft version: 1.0 - 30/July/2008.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

saud_ad
Web Developer
India India
No Biography provided

Comments and Discussions

 
GeneralMy vote of 5 PinmemberManfred R. Bihy31-Mar-11 0:53 
I'm not sure why this article was not appreciated. I liked it rather well. 5

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web01 | 2.8.140415.2 | Last Updated 30 Jul 2008
Article Copyright 2008 by saud_ad
Everything else Copyright © CodeProject, 1999-2014
Terms of Use
Layout: fixed | fluid