65.9K
CodeProject is changing. Read more.
Home

Detecting a Firefox Extension Using JavaScript

starIconstarIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIcon

2.60/5 (4 votes)

Jul 30, 2008

CPOL

2 min read

viewsIcon

29537

The following explanation will help you understand how to detect if a Firefox extension is installed on your system. This also handles the problems you might face using Firefox 3.

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.