Firefox PDF Reader Detector




PDF.js is the official name for the native PDF document viewer in Firefox. Firefox 19 and higher comes with PDF.js already built in. Whereas for Firefox < 19, you had to install PDF.js as a browser addon.

The Firefox PDF Reader detector shown above will tell you when PDF.js is installed & enabled & the default PDF viewer in your browser. When we say "default viewer", we mean that the browser defaults to using that viewer to display PDF documents, even if other PDF viewers (like Adobe Acrobat or Foxit Reader) are installed and enabled in the browser.

Please note that PDF.js does not appear to have any "officially supported" way to detect when it is the default PDF viewer in Firefox. Therefore I have to consider the detection methods used here to be brittle. They could easily break if PDF.js or Firefox change in certain ways. So enjoy it while it lasts. :-)


By the way, we have a small warning for those of you who want to switch between the native PDF.js reader and some other reader (Adobe Reader, Foxit, etc...) in Firefox. Whenever you switch between 2 different pdf viewers in Firefox, you should probably then restart the browser. This will help to ensure that Firefox uses the correct pdf viewer that you intended.

For example, I have a seen a case where Firefox 22 (on Windows) is originally set to display pdf documents using Adobe Reader 11.0.3. When I changed the browser settings so that PDF.js is the default viewer, but did NOT restart the browser, then Firefox sometimes continued to use the Adobe Reader. When I then restarted the browser, Firefox correctly used PDF.js to display pdf documents.

I do not know if this behavior is a browser bug or an intentional feature. Either way, just keep this issue in mind when you test the PDf.js detector at the top of this page.



A few PluginDetect commands for PDF.js detection

PluginDetect.getVersion('PDFjs', DummyPDF): [Returns null]
   Returns null because version info is not available.

PluginDetect.isMinVersion('PDFjs', minVersion, DummyPDF): [Returns number]

   Returns 0 if installed & enabled and is the default PDF viewer in the browser. The version of the viewer is unknown. PDF documents will be displayed in the browser using PDF.js (by default), even if other PDF viewers are installed. [other PDF viewers could be Adobe Reader, Foxit Reader, etc...]

   Returns -0.5 if plugin detection has been initiated but is not yet completed. At this point in time, it is unknown whether the plugin is installed or not. Detection is occurring NOTF (Not On The Fly), so you will have to wait until the detection has completed. Only certain plugins (on certain browsers and platforms) require NOTF.
   In order to handle NOTF detection, it is recommended that you use the onDetectionDone( ) method. This method will call an event handler after plugin detection has fully completed. The handler can call the isMinVersion( ) and getVersion( ) methods to obtain the final plugin detection results.

   Returns -1 if not installed or not enabled or is not the default viewer. PDF.js will NOT be used to display PDF documents in the browser.

   Returns -3 if you supplied a bad input argument to the isMinVersion( ) method.

PluginDetect.onDetectionDone('PDFjs', f, DummyPDF): [Returns number]
   This method will initiate plugin detection when needed, and will execute the event handler f after the plugin detection results become available. The event handler f automatically receives the PluginDetect object as an input argument such that we have f(PluginDetect){ ... }. You are free to use the getVersion( ) and isMinVersion( ) methods inside event handler f.
   onDetectionDone( ) can handle both OTF (on the fly) and NOTF (not on the fly) plugin detection. Because NOTF detection is required for PDF.js, you will have to use the onDetectionDone( ) method to detect PDF.js. You must specify the DummyPDF input argument in order for NOTF detection to occur.
   Returns 1 if plugin detection is done (OTF) and handler f has been called.
   Returns 0 if plugin detection is not done yet (NOTF) and handler f has not been called yet. Handler f will be called after detection has been completed.
   Returns -1 if error (plugin name input argument not specified correctly).

PluginDetect.onBeforeInstantiate('PDFjs', f):
   Executes the event handler f immediately before PluginDetect attempts to insert a DummyPDF into the web page. The event handler automatically receives the PluginDetect object as an input argument such that we have f(PluginDetect){ ... }.
  In order for the onBeforeInstantiate( ) method to work correctly, you must place it BEFORE detection is started for the plugin. In other words, use it before getVersion(pluginName), isMinVersion(pluginName), and onDetectionDone(pluginName). As an example:
       var PD = PluginDetect;
       var F1 = function($){ ... };        // $ input arg is the PluginDetect object
       PD.onBeforeInstantiate('PDFjs', F1);
       var F2 = function($){ var version = $.getVersion('PDFjs'); alert(version); };
       PD.onDetectionDone('PDFjs'', F2, 'empty.pdf');

PluginDetect.onWindowLoaded( f ):
   Executes the event handler f after the browser window has fully loaded. The event handler f automatically receives the PluginDetect object as an input argument such that we have f(PluginDetect){ ... }. You are free to use getVersion( ), isMinVersion( ), onDetectionDone( ), and onBeforeInstantiate( ) inside event handler f.

Event handler f without user input arguments: If the user does not specify any input arguments for event handler f, then the relevant PluginDetect methods are in the format of
       PluginDetect.onDetectionDone(pluginName, f, ...)
       PluginDetect.onWindowLoaded(f)
       PluginDetect.onBeforeInstantiate(pluginName, f)

When the handler f is executed it automatically receives the PluginDetect object as input such that we have f(PluginDetect){ ... }.

Event handler f with user input arguments: You may specify up to 3 inputs (ie. arg1, arg2, and arg3) for the event handler. The trick is to use an array such as [f, arg1, arg2, arg3]. The relevant PluginDetect methods are in the format of
       PluginDetect.onDetectionDone(pluginName, [f, arg1, arg2, arg3], ...)
       PluginDetect.onWindowLoaded( [f, arg1, arg2, arg3] )
       PluginDetect.onBeforeInstantiate(pluginName, [f, arg1, arg2, arg3])

When the handler f is executed it automatically receives the PluginDetect object as input such that we have f(PluginDetect, arg1, arg2, arg3){ ... }.



minVersion: [string or number input argument]
Use a value of '0' here because PluginDetect does not know or care what the PDF.js version is.

DummyPDF: [string input argument, mandatory input arg] 
This is the path/filename to an empty PDF document that is temporarily inserted into the web page. It is used by PluginDetect to see if a browser has PDF capability. You may download the DummyPDF file here. You are free to rename the DummyPDF file to whatever you wish, as long as the .pdf extension remains the same. We tried to make the file as small as possible.
   The path of the DummyPDF can be relative or absolute. If the path is relative, then it is relative to your HTML web page. If you are using isMinVersion( ) in an external javascript file, the path of DummyPDF is NOT relative to the javascript file - it is still relative to the HTML web page. For example,
           DummyPDF = 'empty.pdf' means the file is in the same folder as your web page.
           DummyPDF = 'ABC/empty.pdf' means the file is in a subfolder ABC.

If you specify the DummyPDF path or filename incorrectly, then PDF.js will not be detected. So make sure you get it right. Also, you only need to specify the DummyPDF input argument in the first PDF.js related PluginDetect command that gets executed. All subsequent PluginDetect commands will automatically remember the value of the DummyPDF input argument. However, you are free to specify DummyPDF in all your PluginDetect commands if you wish.




OTF & NOTF Plugin Detection

For a brief discussion of OTF and NOTF plugin detection, please visit this page. The PDF.js plugin can only be detected with NOTF.